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.66 2000/02/15 03:26:38 thomas Exp $
13 *-------------------------------------------------------------------------
18 #include "nodes/parsenodes.h"
19 #include "nodes/pg_list.h"
21 #include "parser/keywords.h"
24 * List of (keyword-name, keyword-token-value) pairs.
26 * !!WARNING!!: This list must be sorted, because binary
27 * search is used to locate entries.
29 static ScanKeyword ScanKeywords[] = {
31 {"abort", ABORT_TRANS},
32 {"absolute", ABSOLUTE},
37 {"aggregate", AGGREGATE},
45 {"backward", BACKWARD},
47 {"begin", BEGIN_TRANS},
57 {"character", CHARACTER},
61 {"coalesce", COALESCE},
66 {"committed", COMMITTED},
67 {"constraint", CONSTRAINT},
68 {"constraints", CONSTRAINTS},
71 {"createdb", CREATEDB},
72 {"createuser", CREATEUSER},
74 {"current_date", CURRENT_DATE},
75 {"current_time", CURRENT_TIME},
76 {"current_timestamp", CURRENT_TIMESTAMP},
77 {"current_user", CURRENT_USER},
80 {"database", DATABASE},
86 {"deferrable", DEFERRABLE},
87 {"deferred", DEFERRED},
89 {"delimiters", DELIMITERS},
91 {"distinct", DISTINCT},
97 {"encoding", ENCODING},
100 {"exclusive", EXCLUSIVE},
101 {"execute", EXECUTE},
103 {"explain", EXPLAIN},
105 {"extract", EXTRACT},
110 {"foreign", FOREIGN},
111 {"forward", FORWARD},
114 {"function", FUNCTION},
118 {"handler", HANDLER},
121 {"immediate", IMMEDIATE},
123 {"increment", INCREMENT},
125 {"inherits", INHERITS},
126 {"initially", INITIALLY},
128 {"insensitive", INSENSITIVE},
130 {"instead", INSTEAD},
131 {"intersect", INTERSECT},
132 {"interval", INTERVAL},
136 {"isolation", ISOLATION},
139 {"lancompiler", LANCOMPILER},
140 {"language", LANGUAGE},
141 {"leading", LEADING},
149 {"location", LOCATION},
152 {"maxvalue", MAXVALUE},
153 {"minute", MINUTE_P},
154 {"minvalue", MINVALUE},
159 {"national", NATIONAL},
160 {"natural", NATURAL},
165 {"nocreatedb", NOCREATEDB},
166 {"nocreateuser", NOCREATEUSER},
169 {"nothing", NOTHING},
171 {"notnull", NOTNULL},
174 {"numeric", NUMERIC},
181 {"operator", OPERATOR},
186 {"partial", PARTIAL},
187 {"password", PASSWORD},
188 {"pendant", PENDANT},
189 {"position", POSITION},
190 {"precision", PRECISION},
191 {"primary", PRIMARY},
193 {"privileges", PRIVILEGES},
194 {"procedural", PROCEDURAL},
195 {"procedure", PROCEDURE},
198 {"references", REFERENCES},
199 {"relative", RELATIVE},
202 {"restrict", RESTRICT},
203 {"returns", RETURNS},
206 {"rollback", ROLLBACK},
210 {"second", SECOND_P},
212 {"sequence", SEQUENCE},
214 {"serializable", SERIALIZABLE},
215 {"session_user", SESSION_USER},
221 {"statement", STATEMENT},
224 {"substring", SUBSTRING},
228 {"temporary", TEMPORARY},
231 {"timestamp", TIMESTAMP},
232 {"timezone_hour", TIMEZONE_HOUR},
233 {"timezone_minute", TIMEZONE_MINUTE},
235 {"trailing", TRAILING},
236 {"transaction", TRANSACTION},
237 {"trigger", TRIGGER},
240 {"truncate", TRUNCATE},
241 {"trusted", TRUSTED},
245 {"unlisten", UNLISTEN},
253 {"varchar", VARCHAR},
254 {"varying", VARYING},
255 {"verbose", VERBOSE},
256 {"version", VERSION},
267 ScanKeywordLookup(char *text)
269 ScanKeyword *low = &ScanKeywords[0];
270 ScanKeyword *high = endof(ScanKeywords) - 1;
276 middle = low + (high - low) / 2;
277 difference = strcmp(middle->name, text);
280 else if (difference < 0)