1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* keywords.c--
|
1997-09-07 07:04:48 +02:00
|
|
|
* lexical token lookup for reserved words in postgres SQL
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
1998-08-25 17:04:24 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.41 1998/08/25 15:04:24 thomas Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
1997-11-26 02:14:33 +01:00
|
|
|
#include "postgres.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "nodes/parsenodes.h"
|
1997-11-26 02:14:33 +01:00
|
|
|
#include "nodes/pg_list.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "parse.h"
|
|
|
|
#include "parser/keywords.h"
|
1997-11-25 23:07:18 +01:00
|
|
|
#include "utils/elog.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* List of (keyword-name, keyword-token-value) pairs.
|
|
|
|
*
|
|
|
|
* !!WARNING!!: This list must be sorted, because binary
|
1997-09-07 07:04:48 +02:00
|
|
|
* search is used to locate entries.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
static ScanKeyword ScanKeywords[] = {
|
1997-09-07 07:04:48 +02:00
|
|
|
/* name value */
|
|
|
|
{"abort", ABORT_TRANS},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"action", ACTION},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"add", ADD},
|
|
|
|
{"after", AFTER},
|
|
|
|
{"aggregate", AGGREGATE},
|
|
|
|
{"all", ALL},
|
|
|
|
{"alter", ALTER},
|
|
|
|
{"analyze", ANALYZE},
|
|
|
|
{"and", AND},
|
1998-01-19 06:06:41 +01:00
|
|
|
{"any", ANY},
|
1997-11-21 19:12:58 +01:00
|
|
|
{"archive", ARCHIVE},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"as", AS},
|
|
|
|
{"asc", ASC},
|
|
|
|
{"backward", BACKWARD},
|
|
|
|
{"before", BEFORE},
|
|
|
|
{"begin", BEGIN_TRANS},
|
|
|
|
{"between", BETWEEN},
|
|
|
|
{"binary", BINARY},
|
|
|
|
{"both", BOTH},
|
|
|
|
{"by", BY},
|
1998-03-18 17:50:25 +01:00
|
|
|
{"cache", CACHE},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"cascade", CASCADE},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"cast", CAST},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"char", CHAR},
|
1997-09-13 05:13:37 +02:00
|
|
|
{"character", CHARACTER},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"check", CHECK},
|
|
|
|
{"close", CLOSE},
|
|
|
|
{"cluster", CLUSTER},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"collate", COLLATE},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"column", COLUMN},
|
|
|
|
{"commit", COMMIT},
|
|
|
|
{"constraint", CONSTRAINT},
|
|
|
|
{"copy", COPY},
|
|
|
|
{"create", CREATE},
|
1997-12-04 01:28:15 +01:00
|
|
|
{"createdb", CREATEDB},
|
|
|
|
{"createuser", CREATEUSER},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"cross", CROSS},
|
1998-08-24 03:38:11 +02:00
|
|
|
{"current", CURRENT}, /*
|
|
|
|
* 6.4 to 6.5 is migration time!
|
|
|
|
* CURRENT will be removed in 6.5!
|
|
|
|
* Use OLD keyword in rules.
|
|
|
|
* Jan
|
|
|
|
*/
|
1997-09-24 19:49:56 +02:00
|
|
|
{"current_date", CURRENT_DATE},
|
|
|
|
{"current_time", CURRENT_TIME},
|
|
|
|
{"current_timestamp", CURRENT_TIMESTAMP},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"current_user", CURRENT_USER},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"cursor", CURSOR},
|
1998-03-18 17:50:25 +01:00
|
|
|
{"cycle", CYCLE},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"database", DATABASE},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"day", DAY_P},
|
1997-09-24 19:49:56 +02:00
|
|
|
{"decimal", DECIMAL},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"declare", DECLARE},
|
|
|
|
{"default", DEFAULT},
|
|
|
|
{"delete", DELETE},
|
|
|
|
{"delimiters", DELIMITERS},
|
|
|
|
{"desc", DESC},
|
|
|
|
{"distinct", DISTINCT},
|
|
|
|
{"do", DO},
|
1997-09-13 05:13:37 +02:00
|
|
|
{"double", DOUBLE},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"drop", DROP},
|
1998-02-11 05:09:54 +01:00
|
|
|
{"each", EACH},
|
1998-07-24 05:32:46 +02:00
|
|
|
{"encoding", ENCODING},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"end", END_TRANS},
|
|
|
|
{"execute", EXECUTE},
|
|
|
|
{"exists", EXISTS},
|
|
|
|
{"explain", EXPLAIN},
|
|
|
|
{"extend", EXTEND},
|
|
|
|
{"extract", EXTRACT},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"false", FALSE_P},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"fetch", FETCH},
|
1997-09-20 18:11:44 +02:00
|
|
|
{"float", FLOAT},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"for", FOR},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"foreign", FOREIGN},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"forward", FORWARD},
|
|
|
|
{"from", FROM},
|
|
|
|
{"full", FULL},
|
|
|
|
{"function", FUNCTION},
|
|
|
|
{"grant", GRANT},
|
|
|
|
{"group", GROUP},
|
1997-10-28 16:11:45 +01:00
|
|
|
{"handler", HANDLER},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"having", HAVING},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"hour", HOUR_P},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"in", IN},
|
1998-03-18 17:50:25 +01:00
|
|
|
{"increment", INCREMENT},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"index", INDEX},
|
|
|
|
{"inherits", INHERITS},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"inner", INNER_P},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"insert", INSERT},
|
|
|
|
{"instead", INSTEAD},
|
|
|
|
{"interval", INTERVAL},
|
|
|
|
{"into", INTO},
|
|
|
|
{"is", IS},
|
|
|
|
{"isnull", ISNULL},
|
|
|
|
{"join", JOIN},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"key", KEY},
|
1997-10-28 16:11:45 +01:00
|
|
|
{"lancompiler", LANCOMPILER},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"language", LANGUAGE},
|
|
|
|
{"leading", LEADING},
|
|
|
|
{"left", LEFT},
|
|
|
|
{"like", LIKE},
|
|
|
|
{"listen", LISTEN},
|
|
|
|
{"load", LOAD},
|
|
|
|
{"local", LOCAL},
|
1997-11-07 08:02:10 +01:00
|
|
|
{"location", LOCATION},
|
1998-01-23 00:05:18 +01:00
|
|
|
{"lock", LOCK_P},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"match", MATCH},
|
1998-03-18 17:50:25 +01:00
|
|
|
{"maxvalue", MAXVALUE},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"minute", MINUTE_P},
|
1998-03-18 17:50:25 +01:00
|
|
|
{"minvalue", MINVALUE},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"month", MONTH_P},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"move", MOVE},
|
1998-07-24 05:32:46 +02:00
|
|
|
{"names", NAMES},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"national", NATIONAL},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"natural", NATURAL},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"nchar", NCHAR},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"new", NEW},
|
1997-12-16 06:04:00 +01:00
|
|
|
{"no", NO},
|
1997-12-04 01:28:15 +01:00
|
|
|
{"nocreatedb", NOCREATEDB},
|
|
|
|
{"nocreateuser", NOCREATEUSER},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"none", NONE},
|
|
|
|
{"not", NOT},
|
|
|
|
{"nothing", NOTHING},
|
|
|
|
{"notify", NOTIFY},
|
|
|
|
{"notnull", NOTNULL},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"null", NULL_P},
|
1997-09-24 19:49:56 +02:00
|
|
|
{"numeric", NUMERIC},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"oids", OIDS},
|
1998-08-24 03:39:18 +02:00
|
|
|
{"old", CURRENT},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"on", ON},
|
|
|
|
{"operator", OPERATOR},
|
|
|
|
{"option", OPTION},
|
|
|
|
{"or", OR},
|
|
|
|
{"order", ORDER},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"outer", OUTER_P},
|
|
|
|
{"partial", PARTIAL},
|
1997-12-04 01:28:15 +01:00
|
|
|
{"password", PASSWORD},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"position", POSITION},
|
1997-09-13 05:13:37 +02:00
|
|
|
{"precision", PRECISION},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"primary", PRIMARY},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"privileges", PRIVILEGES},
|
1997-10-28 16:11:45 +01:00
|
|
|
{"procedural", PROCEDURAL},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"procedure", PROCEDURE},
|
|
|
|
{"public", PUBLIC},
|
|
|
|
{"recipe", RECIPE},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"references", REFERENCES},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"rename", RENAME},
|
|
|
|
{"reset", RESET},
|
|
|
|
{"returns", RETURNS},
|
|
|
|
{"revoke", REVOKE},
|
|
|
|
{"right", RIGHT},
|
|
|
|
{"rollback", ROLLBACK},
|
1998-02-11 05:09:54 +01:00
|
|
|
{"row", ROW},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"rule", RULE},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"second", SECOND_P},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"select", SELECT},
|
|
|
|
{"sequence", SEQUENCE},
|
1998-08-25 17:04:24 +02:00
|
|
|
{"serial", SERIAL},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"set", SET},
|
|
|
|
{"setof", SETOF},
|
|
|
|
{"show", SHOW},
|
1998-03-18 17:50:25 +01:00
|
|
|
{"start", START},
|
1998-02-11 05:09:54 +01:00
|
|
|
{"statement", STATEMENT},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"stdin", STDIN},
|
|
|
|
{"stdout", STDOUT},
|
|
|
|
{"substring", SUBSTRING},
|
|
|
|
{"table", TABLE},
|
|
|
|
{"time", TIME},
|
1998-05-10 01:28:49 +02:00
|
|
|
{"timezone_hour", TIMEZONE_HOUR},
|
|
|
|
{"timezone_minute", TIMEZONE_MINUTE},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"to", TO},
|
|
|
|
{"trailing", TRAILING},
|
1997-09-13 05:13:37 +02:00
|
|
|
{"transaction", TRANSACTION},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"trigger", TRIGGER},
|
|
|
|
{"trim", TRIM},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"true", TRUE_P},
|
1997-10-28 16:11:45 +01:00
|
|
|
{"trusted", TRUSTED},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"type", TYPE_P},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"union", UNION},
|
|
|
|
{"unique", UNIQUE},
|
1997-12-04 01:28:15 +01:00
|
|
|
{"until", UNTIL},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"update", UPDATE},
|
1997-12-04 01:28:15 +01:00
|
|
|
{"user", USER},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"using", USING},
|
|
|
|
{"vacuum", VACUUM},
|
1997-12-04 01:28:15 +01:00
|
|
|
{"valid", VALID},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"values", VALUES},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"varchar", VARCHAR},
|
1997-09-13 05:13:37 +02:00
|
|
|
{"varying", VARYING},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"verbose", VERBOSE},
|
|
|
|
{"version", VERSION},
|
|
|
|
{"view", VIEW},
|
|
|
|
{"where", WHERE},
|
|
|
|
{"with", WITH},
|
|
|
|
{"work", WORK},
|
1997-10-25 07:44:11 +02:00
|
|
|
{"year", YEAR_P},
|
1997-09-07 07:04:48 +02:00
|
|
|
{"zone", ZONE},
|
1996-07-09 08:22:35 +02:00
|
|
|
};
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
ScanKeyword *
|
1996-07-09 08:22:35 +02:00
|
|
|
ScanKeywordLookup(char *text)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
ScanKeyword *low = &ScanKeywords[0];
|
|
|
|
ScanKeyword *high = endof(ScanKeywords) - 1;
|
|
|
|
ScanKeyword *middle;
|
|
|
|
int difference;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
while (low <= high)
|
|
|
|
{
|
|
|
|
middle = low + (high - low) / 2;
|
|
|
|
difference = strcmp(middle->name, text);
|
|
|
|
if (difference == 0)
|
|
|
|
return (middle);
|
|
|
|
else if (difference < 0)
|
|
|
|
low = middle + 1;
|
|
|
|
else
|
|
|
|
high = middle - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|