]> granicus.if.org Git - postgresql/blob - src/backend/parser/keywords.c
848f1dc8d6b8d33fa9f658ef5baa241806ee5803
[postgresql] / src / backend / parser / keywords.c
1 /*-------------------------------------------------------------------------
2  *
3  * keywords.c
4  *        lexical token lookup for reserved words in postgres SQL
5  *
6  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *        $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.80 2000/08/06 18:05:22 thomas Exp $
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include <ctype.h>
16
17 #include "postgres.h"
18
19 #include "nodes/parsenodes.h"
20 #include "nodes/pg_list.h"
21 #include "parser/keywords.h"
22 #include "parser/parse.h"
23
24 /*
25  * List of (keyword-name, keyword-token-value) pairs.
26  *
27  * !!WARNING!!: This list must be sorted, because binary
28  *               search is used to locate entries.
29  */
30 static ScanKeyword ScanKeywords[] = {
31         /* name, value */
32         {"abort", ABORT_TRANS},
33         {"absolute", ABSOLUTE},
34         {"access", ACCESS},
35         {"action", ACTION},
36         {"add", ADD},
37         {"after", AFTER},
38         {"aggregate", AGGREGATE},
39         {"all", ALL},
40         {"alter", ALTER},
41         {"analyze", ANALYZE},
42         {"and", AND},
43         {"any", ANY},
44         {"as", AS},
45         {"asc", ASC},
46         {"backward", BACKWARD},
47         {"before", BEFORE},
48         {"begin", BEGIN_TRANS},
49         {"between", BETWEEN},
50         {"binary", BINARY},
51         {"bit", BIT},
52         {"both", BOTH},
53         {"by", BY},
54         {"cache", CACHE},
55         {"cascade", CASCADE},
56         {"case", CASE},
57         {"cast", CAST},
58         {"chain", CHAIN},
59         {"char", CHAR},
60         {"character", CHARACTER},
61         {"characteristics", CHARACTERISTICS},
62         {"check", CHECK},
63         {"close", CLOSE},
64         {"cluster", CLUSTER},
65         {"coalesce", COALESCE},
66         {"collate", COLLATE},
67         {"column", COLUMN},
68         {"comment", COMMENT},
69         {"commit", COMMIT},
70         {"committed", COMMITTED},
71         {"constraint", CONSTRAINT},
72         {"constraints", CONSTRAINTS},
73         {"copy", COPY},
74         {"create", CREATE},
75         {"createdb", CREATEDB},
76         {"createuser", CREATEUSER},
77         {"cross", CROSS},
78         /* for portability with old rules bjm 2000-06-12 */
79         {"current", OLD},
80         {"current_date", CURRENT_DATE},
81         {"current_time", CURRENT_TIME},
82         {"current_timestamp", CURRENT_TIMESTAMP},
83         {"current_user", CURRENT_USER},
84         {"cursor", CURSOR},
85         {"cycle", CYCLE},
86         {"database", DATABASE},
87         {"day", DAY_P},
88         {"dec", DEC},
89         {"decimal", DECIMAL},
90         {"declare", DECLARE},
91         {"default", DEFAULT},
92         {"deferrable", DEFERRABLE},
93         {"deferred", DEFERRED},
94         {"delete", DELETE},
95         {"delimiters", DELIMITERS},
96         {"desc", DESC},
97         {"distinct", DISTINCT},
98         {"do", DO},
99         {"double", DOUBLE},
100         {"drop", DROP},
101         {"each", EACH},
102         {"else", ELSE},
103         {"encoding", ENCODING},
104         {"end", END_TRANS},
105         {"escape", ESCAPE},
106         {"except", EXCEPT},
107         {"exclusive", EXCLUSIVE},
108         {"execute", EXECUTE},
109         {"exists", EXISTS},
110         {"explain", EXPLAIN},
111         {"extend", EXTEND},
112         {"extract", EXTRACT},
113         {"false", FALSE_P},
114         {"fetch", FETCH},
115         {"float", FLOAT},
116         {"for", FOR},
117         {"force", FORCE},
118         {"foreign", FOREIGN},
119         {"forward", FORWARD},
120         {"from", FROM},
121         {"full", FULL},
122         {"function", FUNCTION},
123         {"global", GLOBAL},
124         {"grant", GRANT},
125         {"group", GROUP},
126         {"handler", HANDLER},
127         {"having", HAVING},
128         {"hour", HOUR_P},
129         {"ilike", ILIKE},
130         {"immediate", IMMEDIATE},
131         {"in", IN},
132         {"increment", INCREMENT},
133         {"index", INDEX},
134         {"inherits", INHERITS},
135         {"initially", INITIALLY},
136         {"inner", INNER_P},
137         {"inout", INOUT},
138         {"insensitive", INSENSITIVE},
139         {"insert", INSERT},
140         {"instead", INSTEAD},
141         {"intersect", INTERSECT},
142         {"interval", INTERVAL},
143         {"into", INTO},
144         {"is", IS},
145         {"isnull", ISNULL},
146         {"isolation", ISOLATION},
147         {"join", JOIN},
148         {"key", KEY},
149         {"lancompiler", LANCOMPILER},
150         {"language", LANGUAGE},
151         {"leading", LEADING},
152         {"left", LEFT},
153         {"level", LEVEL},
154         {"like", LIKE},
155         {"limit", LIMIT},
156         {"listen", LISTEN},
157         {"load", LOAD},
158         {"local", LOCAL},
159         {"location", LOCATION},
160         {"lock", LOCK_P},
161         {"match", MATCH},
162         {"maxvalue", MAXVALUE},
163         {"minute", MINUTE_P},
164         {"minvalue", MINVALUE},
165         {"mode", MODE},
166         {"month", MONTH_P},
167         {"move", MOVE},
168         {"names", NAMES},
169         {"national", NATIONAL},
170         {"natural", NATURAL},
171         {"nchar", NCHAR},
172         {"new", NEW},
173         {"next", NEXT},
174         {"no", NO},
175         {"nocreatedb", NOCREATEDB},
176         {"nocreateuser", NOCREATEUSER},
177         {"none", NONE},
178         {"not", NOT},
179         {"nothing", NOTHING},
180         {"notify", NOTIFY},
181         {"notnull", NOTNULL},
182         {"null", NULL_P},
183         {"nullif", NULLIF},
184         {"numeric", NUMERIC},
185         {"of", OF},
186         {"off", OFF},
187         {"offset", OFFSET},
188         {"oids", OIDS},
189         {"old", OLD},
190         {"on", ON},
191         {"only", ONLY},
192         {"operator", OPERATOR},
193         {"option", OPTION},
194         {"or", OR},
195         {"order", ORDER},
196         {"out", OUT},
197         {"outer", OUTER_P},
198         {"overlaps", OVERLAPS},
199         {"partial", PARTIAL},
200         {"password", PASSWORD},
201         {"path", PATH_P},
202         {"pendant", PENDANT},
203         {"position", POSITION},
204         {"precision", PRECISION},
205         {"primary", PRIMARY},
206         {"prior", PRIOR},
207         {"privileges", PRIVILEGES},
208         {"procedural", PROCEDURAL},
209         {"procedure", PROCEDURE},
210         {"public", PUBLIC},
211         {"read", READ},
212         {"references", REFERENCES},
213         {"reindex", REINDEX},
214         {"relative", RELATIVE},
215         {"rename", RENAME},
216         {"reset", RESET},
217         {"restrict", RESTRICT},
218         {"returns", RETURNS},
219         {"revoke", REVOKE},
220         {"right", RIGHT},
221         {"rollback", ROLLBACK},
222         {"row", ROW},
223         {"rule", RULE},
224         {"schema", SCHEMA},
225         {"scroll", SCROLL},
226         {"second", SECOND_P},
227         {"select", SELECT},
228         {"sequence", SEQUENCE},
229         {"serial", SERIAL},
230         {"serializable", SERIALIZABLE},
231         {"session", SESSION},
232         {"session_user", SESSION_USER},
233         {"set", SET},
234         {"setof", SETOF},
235         {"share", SHARE},
236         {"show", SHOW},
237         {"some", SOME},
238         {"start", START},
239         {"statement", STATEMENT},
240         {"stdin", STDIN},
241         {"stdout", STDOUT},
242         {"substring", SUBSTRING},
243         {"sysid", SYSID},
244         {"table", TABLE},
245         {"temp", TEMP},
246         {"temporary", TEMPORARY},
247         {"then", THEN},
248         {"time", TIME},
249         {"timestamp", TIMESTAMP},
250         {"timezone_hour", TIMEZONE_HOUR},
251         {"timezone_minute", TIMEZONE_MINUTE},
252         {"to", TO},
253         {"toast", TOAST},
254         {"trailing", TRAILING},
255         {"transaction", TRANSACTION},
256         {"trigger", TRIGGER},
257         {"trim", TRIM},
258         {"true", TRUE_P},
259         {"truncate", TRUNCATE},
260         {"trusted", TRUSTED},
261         {"type", TYPE_P},
262         {"under", UNDER},
263         {"union", UNION},
264         {"unique", UNIQUE},
265         {"unlisten", UNLISTEN},
266         {"until", UNTIL},
267         {"update", UPDATE},
268         {"user", USER},
269         {"using", USING},
270         {"vacuum", VACUUM},
271         {"valid", VALID},
272         {"values", VALUES},
273         {"varchar", VARCHAR},
274         {"varying", VARYING},
275         {"verbose", VERBOSE},
276         {"version", VERSION},
277         {"view", VIEW},
278         {"when", WHEN},
279         {"where", WHERE},
280         {"with", WITH},
281         {"without", WITHOUT},
282         {"work", WORK},
283         {"year", YEAR_P},
284         {"zone", ZONE},
285 };
286
287 ScanKeyword *
288 ScanKeywordLookup(char *text)
289 {
290         ScanKeyword *low = &ScanKeywords[0];
291         ScanKeyword *high = endof(ScanKeywords) - 1;
292         ScanKeyword *middle;
293         int                     difference;
294
295         while (low <= high)
296         {
297                 middle = low + (high - low) / 2;
298                 difference = strcmp(middle->name, text);
299                 if (difference == 0)
300                         return middle;
301                 else if (difference < 0)
302                         low = middle + 1;
303                 else
304                         high = middle - 1;
305         }
306
307         return NULL;
308 }