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