1 /*-------------------------------------------------------------------------
4 * lexical token lookup for reserved words in postgres SQL
6 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.79 2000/07/14 15:43:32 thomas Exp $
13 *-------------------------------------------------------------------------
19 #include "nodes/parsenodes.h"
20 #include "nodes/pg_list.h"
21 #include "parser/keywords.h"
22 #include "parser/parse.h"
25 * List of (keyword-name, keyword-token-value) pairs.
27 * !!WARNING!!: This list must be sorted, because binary
28 * search is used to locate entries.
30 static ScanKeyword ScanKeywords[] = {
32 {"abort", ABORT_TRANS},
33 {"absolute", ABSOLUTE},
38 {"aggregate", AGGREGATE},
46 {"backward", BACKWARD},
48 {"begin", BEGIN_TRANS},
59 {"character", CHARACTER},
60 {"characteristics", CHARACTERISTICS},
64 {"coalesce", COALESCE},
69 {"committed", COMMITTED},
70 {"constraint", CONSTRAINT},
71 {"constraints", CONSTRAINTS},
74 {"createdb", CREATEDB},
75 {"createuser", CREATEUSER},
77 /* for portability with old rules bjm 2000-06-12 */
79 {"current_date", CURRENT_DATE},
80 {"current_time", CURRENT_TIME},
81 {"current_timestamp", CURRENT_TIMESTAMP},
82 {"current_user", CURRENT_USER},
85 {"database", DATABASE},
91 {"deferrable", DEFERRABLE},
92 {"deferred", DEFERRED},
94 {"delimiters", DELIMITERS},
96 {"distinct", DISTINCT},
102 {"encoding", ENCODING},
105 {"exclusive", EXCLUSIVE},
106 {"execute", EXECUTE},
108 {"explain", EXPLAIN},
110 {"extract", EXTRACT},
116 {"foreign", FOREIGN},
117 {"forward", FORWARD},
120 {"function", FUNCTION},
124 {"handler", HANDLER},
127 {"immediate", IMMEDIATE},
129 {"increment", INCREMENT},
131 {"inherits", INHERITS},
132 {"initially", INITIALLY},
135 {"insensitive", INSENSITIVE},
137 {"instead", INSTEAD},
138 {"intersect", INTERSECT},
139 {"interval", INTERVAL},
143 {"isolation", ISOLATION},
146 {"lancompiler", LANCOMPILER},
147 {"language", LANGUAGE},
148 {"leading", LEADING},
156 {"location", LOCATION},
159 {"maxvalue", MAXVALUE},
160 {"minute", MINUTE_P},
161 {"minvalue", MINVALUE},
166 {"national", NATIONAL},
167 {"natural", NATURAL},
172 {"nocreatedb", NOCREATEDB},
173 {"nocreateuser", NOCREATEUSER},
176 {"nothing", NOTHING},
178 {"notnull", NOTNULL},
181 {"numeric", NUMERIC},
189 {"operator", OPERATOR},
195 {"overlaps", OVERLAPS},
196 {"partial", PARTIAL},
197 {"password", PASSWORD},
199 {"pendant", PENDANT},
200 {"position", POSITION},
201 {"precision", PRECISION},
202 {"primary", PRIMARY},
204 {"privileges", PRIVILEGES},
205 {"procedural", PROCEDURAL},
206 {"procedure", PROCEDURE},
209 {"references", REFERENCES},
210 {"reindex", REINDEX},
211 {"relative", RELATIVE},
214 {"restrict", RESTRICT},
215 {"returns", RETURNS},
218 {"rollback", ROLLBACK},
223 {"second", SECOND_P},
225 {"sequence", SEQUENCE},
227 {"serializable", SERIALIZABLE},
228 {"session", SESSION},
229 {"session_user", SESSION_USER},
236 {"statement", STATEMENT},
239 {"substring", SUBSTRING},
243 {"temporary", TEMPORARY},
246 {"timestamp", TIMESTAMP},
247 {"timezone_hour", TIMEZONE_HOUR},
248 {"timezone_minute", TIMEZONE_MINUTE},
251 {"trailing", TRAILING},
252 {"transaction", TRANSACTION},
253 {"trigger", TRIGGER},
256 {"truncate", TRUNCATE},
257 {"trusted", TRUSTED},
262 {"unlisten", UNLISTEN},
270 {"varchar", VARCHAR},
271 {"varying", VARYING},
272 {"verbose", VERBOSE},
273 {"version", VERSION},
278 {"without", WITHOUT},
285 ScanKeywordLookup(char *text)
287 ScanKeyword *low = &ScanKeywords[0];
288 ScanKeyword *high = endof(ScanKeywords) - 1;
294 middle = low + (high - low) / 2;
295 difference = strcmp(middle->name, text);
298 else if (difference < 0)