1 /*-------------------------------------------------------------------------
4 * lexical token lookup for reserved words in postgres SQL
6 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.88 2001/01/24 19:43:01 momjian 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},
41 {"analyse", ANALYSE}, /* British spelling */
48 {"backward", BACKWARD},
50 {"begin", BEGIN_TRANS},
62 {"character", CHARACTER},
63 {"characteristics", CHARACTERISTICS},
65 {"checkpoint", CHECKPOINT},
68 {"coalesce", COALESCE},
73 {"committed", COMMITTED},
74 {"constraint", CONSTRAINT},
75 {"constraints", CONSTRAINTS},
78 {"createdb", CREATEDB},
79 {"createuser", CREATEUSER},
81 {"current_date", CURRENT_DATE},
82 {"current_time", CURRENT_TIME},
83 {"current_timestamp", CURRENT_TIMESTAMP},
84 {"current_user", CURRENT_USER},
87 {"database", DATABASE},
93 {"deferrable", DEFERRABLE},
94 {"deferred", DEFERRED},
96 {"delimiters", DELIMITERS},
98 {"distinct", DISTINCT},
104 {"encoding", ENCODING},
108 {"exclusive", EXCLUSIVE},
109 {"execute", EXECUTE},
111 {"explain", EXPLAIN},
113 {"extract", EXTRACT},
119 {"foreign", FOREIGN},
120 {"forward", FORWARD},
123 {"function", FUNCTION},
127 {"handler", HANDLER},
131 {"immediate", IMMEDIATE},
133 {"increment", INCREMENT},
135 {"inherits", INHERITS},
136 {"initially", INITIALLY},
139 {"insensitive", INSENSITIVE},
141 {"instead", INSTEAD},
142 {"intersect", INTERSECT},
143 {"interval", INTERVAL},
147 {"isolation", ISOLATION},
150 {"lancompiler", LANCOMPILER},
151 {"language", LANGUAGE},
152 {"leading", LEADING},
160 {"location", LOCATION},
163 {"maxvalue", MAXVALUE},
164 {"minute", MINUTE_P},
165 {"minvalue", MINVALUE},
170 {"national", NATIONAL},
171 {"natural", NATURAL},
176 {"nocreatedb", NOCREATEDB},
177 {"nocreateuser", NOCREATEUSER},
180 {"nothing", NOTHING},
182 {"notnull", NOTNULL},
185 {"numeric", NUMERIC},
193 {"operator", OPERATOR},
199 {"overlaps", OVERLAPS},
201 {"partial", PARTIAL},
202 {"password", PASSWORD},
204 {"pendant", PENDANT},
205 {"position", POSITION},
206 {"precision", PRECISION},
207 {"primary", PRIMARY},
209 {"privileges", PRIVILEGES},
210 {"procedural", PROCEDURAL},
211 {"procedure", PROCEDURE},
214 {"references", REFERENCES},
215 {"reindex", REINDEX},
216 {"relative", RELATIVE},
219 {"restrict", RESTRICT},
220 {"returns", RETURNS},
223 {"rollback", ROLLBACK},
228 {"second", SECOND_P},
230 {"sequence", SEQUENCE},
232 {"serializable", SERIALIZABLE},
233 {"session", SESSION},
234 {"session_user", SESSION_USER},
241 {"statement", STATEMENT},
244 {"substring", SUBSTRING},
248 {"template", TEMPLATE},
249 {"temporary", TEMPORARY},
252 {"timestamp", TIMESTAMP},
253 {"timezone_hour", TIMEZONE_HOUR},
254 {"timezone_minute", TIMEZONE_MINUTE},
257 {"trailing", TRAILING},
258 {"transaction", TRANSACTION},
259 {"trigger", TRIGGER},
262 {"truncate", TRUNCATE},
263 {"trusted", TRUSTED},
267 {"unlisten", UNLISTEN},
275 {"varchar", VARCHAR},
276 {"varying", VARYING},
277 {"verbose", VERBOSE},
278 {"version", VERSION},
283 {"without", WITHOUT},
290 ScanKeywordLookup(char *text)
292 ScanKeyword *low = &ScanKeywords[0];
293 ScanKeyword *high = endof(ScanKeywords) - 1;
299 middle = low + (high - low) / 2;
300 difference = strcmp(middle->name, text);
303 else if (difference < 0)