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