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/interfaces/ecpg/preproc/keywords.c,v 1.27 2000/06/09 01:44:31 momjian Exp $
13 *-------------------------------------------------------------------------
18 #include "nodes/parsenodes.h"
19 #include "nodes/pg_list.h"
22 #include "parser/keywords.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},
63 {"coalesce", COALESCE},
68 {"committed", COMMITTED},
69 {"constraint", CONSTRAINT},
70 {"constraints", CONSTRAINTS},
73 {"createdb", CREATEDB},
74 {"createuser", CREATEUSER},
76 {"current_date", CURRENT_DATE},
77 {"current_time", CURRENT_TIME},
78 {"current_timestamp", CURRENT_TIMESTAMP},
79 {"current_user", CURRENT_USER},
82 {"database", DATABASE},
88 {"deferrable", DEFERRABLE},
89 {"deferred", DEFERRED},
91 {"delimiters", DELIMITERS},
93 {"distinct", DISTINCT},
99 {"encoding", ENCODING},
102 {"exclusive", EXCLUSIVE},
103 {"execute", EXECUTE},
105 {"explain", EXPLAIN},
107 {"extract", EXTRACT},
113 {"foreign", FOREIGN},
114 {"forward", FORWARD},
117 {"function", FUNCTION},
121 {"handler", HANDLER},
124 {"immediate", IMMEDIATE},
126 {"increment", INCREMENT},
128 {"inherits", INHERITS},
129 {"initially", INITIALLY},
131 {"insensitive", INSENSITIVE},
133 {"instead", INSTEAD},
134 {"intersect", INTERSECT},
135 {"interval", INTERVAL},
139 {"isolation", ISOLATION},
142 {"lancompiler", LANCOMPILER},
143 {"language", LANGUAGE},
144 {"leading", LEADING},
152 {"location", LOCATION},
155 {"maxvalue", MAXVALUE},
156 {"minute", MINUTE_P},
157 {"minvalue", MINVALUE},
162 {"national", NATIONAL},
163 {"natural", NATURAL},
168 {"nocreatedb", NOCREATEDB},
169 {"nocreateuser", NOCREATEUSER},
172 {"nothing", NOTHING},
174 {"notnull", NOTNULL},
177 {"numeric", NUMERIC},
184 {"operator", OPERATOR},
186 {"overlaps", OVERLAPS},
190 {"partial", PARTIAL},
191 {"password", PASSWORD},
192 {"pendant", PENDANT},
193 {"position", POSITION},
194 {"precision", PRECISION},
195 {"primary", PRIMARY},
197 {"privileges", PRIVILEGES},
198 {"procedural", PROCEDURAL},
199 {"procedure", PROCEDURE},
202 {"references", REFERENCES},
203 {"reindex", REINDEX},
204 {"relative", RELATIVE},
207 {"restrict", RESTRICT},
208 {"returns", RETURNS},
211 {"rollback", ROLLBACK},
215 {"second", SECOND_P},
217 {"sequence", SEQUENCE},
219 {"serializable", SERIALIZABLE},
220 {"session_user", SESSION_USER},
227 {"statement", STATEMENT},
230 {"substring", SUBSTRING},
234 {"temporary", TEMPORARY},
237 {"timestamp", TIMESTAMP},
238 {"timezone_hour", TIMEZONE_HOUR},
239 {"timezone_minute", TIMEZONE_MINUTE},
241 {"trailing", TRAILING},
242 {"transaction", TRANSACTION},
243 {"trigger", TRIGGER},
246 {"truncate", TRUNCATE},
247 {"trusted", TRUSTED},
252 {"unlisten", UNLISTEN},
260 {"varchar", VARCHAR},
261 {"varying", VARYING},
262 {"verbose", VERBOSE},
263 {"version", VERSION},
274 ScanKeywordLookup(char *text)
276 ScanKeyword *low = &ScanKeywords[0];
277 ScanKeyword *high = endof(ScanKeywords) - 1;
283 middle = low + (high - low) / 2;
284 difference = strcmp(middle->name, text);
287 else if (difference < 0)