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.80 2000/08/06 18:05:22 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},
60 {"character", CHARACTER},
61 {"characteristics", CHARACTERISTICS},
65 {"coalesce", COALESCE},
70 {"committed", COMMITTED},
71 {"constraint", CONSTRAINT},
72 {"constraints", CONSTRAINTS},
75 {"createdb", CREATEDB},
76 {"createuser", CREATEUSER},
78 /* for portability with old rules bjm 2000-06-12 */
80 {"current_date", CURRENT_DATE},
81 {"current_time", CURRENT_TIME},
82 {"current_timestamp", CURRENT_TIMESTAMP},
83 {"current_user", CURRENT_USER},
86 {"database", DATABASE},
92 {"deferrable", DEFERRABLE},
93 {"deferred", DEFERRED},
95 {"delimiters", DELIMITERS},
97 {"distinct", DISTINCT},
103 {"encoding", ENCODING},
107 {"exclusive", EXCLUSIVE},
108 {"execute", EXECUTE},
110 {"explain", EXPLAIN},
112 {"extract", EXTRACT},
118 {"foreign", FOREIGN},
119 {"forward", FORWARD},
122 {"function", FUNCTION},
126 {"handler", HANDLER},
130 {"immediate", IMMEDIATE},
132 {"increment", INCREMENT},
134 {"inherits", INHERITS},
135 {"initially", INITIALLY},
138 {"insensitive", INSENSITIVE},
140 {"instead", INSTEAD},
141 {"intersect", INTERSECT},
142 {"interval", INTERVAL},
146 {"isolation", ISOLATION},
149 {"lancompiler", LANCOMPILER},
150 {"language", LANGUAGE},
151 {"leading", LEADING},
159 {"location", LOCATION},
162 {"maxvalue", MAXVALUE},
163 {"minute", MINUTE_P},
164 {"minvalue", MINVALUE},
169 {"national", NATIONAL},
170 {"natural", NATURAL},
175 {"nocreatedb", NOCREATEDB},
176 {"nocreateuser", NOCREATEUSER},
179 {"nothing", NOTHING},
181 {"notnull", NOTNULL},
184 {"numeric", NUMERIC},
192 {"operator", OPERATOR},
198 {"overlaps", OVERLAPS},
199 {"partial", PARTIAL},
200 {"password", PASSWORD},
202 {"pendant", PENDANT},
203 {"position", POSITION},
204 {"precision", PRECISION},
205 {"primary", PRIMARY},
207 {"privileges", PRIVILEGES},
208 {"procedural", PROCEDURAL},
209 {"procedure", PROCEDURE},
212 {"references", REFERENCES},
213 {"reindex", REINDEX},
214 {"relative", RELATIVE},
217 {"restrict", RESTRICT},
218 {"returns", RETURNS},
221 {"rollback", ROLLBACK},
226 {"second", SECOND_P},
228 {"sequence", SEQUENCE},
230 {"serializable", SERIALIZABLE},
231 {"session", SESSION},
232 {"session_user", SESSION_USER},
239 {"statement", STATEMENT},
242 {"substring", SUBSTRING},
246 {"temporary", TEMPORARY},
249 {"timestamp", TIMESTAMP},
250 {"timezone_hour", TIMEZONE_HOUR},
251 {"timezone_minute", TIMEZONE_MINUTE},
254 {"trailing", TRAILING},
255 {"transaction", TRANSACTION},
256 {"trigger", TRIGGER},
259 {"truncate", TRUNCATE},
260 {"trusted", TRUSTED},
265 {"unlisten", UNLISTEN},
273 {"varchar", VARCHAR},
274 {"varying", VARYING},
275 {"verbose", VERBOSE},
276 {"version", VERSION},
281 {"without", WITHOUT},
288 ScanKeywordLookup(char *text)
290 ScanKeyword *low = &ScanKeywords[0];
291 ScanKeyword *high = endof(ScanKeywords) - 1;
297 middle = low + (high - low) / 2;
298 difference = strcmp(middle->name, text);
301 else if (difference < 0)