1#
2# Copyright (C) 2009-2020 the sqlparse authors and contributors
3# <see AUTHORS file>
4#
5# This module is part of python-sqlparse and is released under
6# the BSD License: https://opensource.org/licenses/BSD-3-Clause
7
8from sqlparse import tokens
9
10# object() only supports "is" and is useful as a marker
11# use this marker to specify that the given regex in SQL_REGEX
12# shall be processed further through a lookup in the KEYWORDS dictionaries
13PROCESS_AS_KEYWORD = object()
14
15
16SQL_REGEX = [
17 (r'(--|# )\+.*?(\r\n|\r|\n|$)', tokens.Comment.Single.Hint),
18 (r'/\*\+[\s\S]*?\*/', tokens.Comment.Multiline.Hint),
19
20 (r'(--|# ).*?(\r\n|\r|\n|$)', tokens.Comment.Single),
21 (r'/\*[\s\S]*?\*/', tokens.Comment.Multiline),
22
23 (r'(\r\n|\r|\n)', tokens.Newline),
24 (r'\s+?', tokens.Whitespace),
25
26 (r':=', tokens.Assignment),
27 (r'::', tokens.Punctuation),
28
29 (r'\*', tokens.Wildcard),
30
31 (r"`(``|[^`])*`", tokens.Name),
32 (r"´(´´|[^´])*´", tokens.Name),
33 (r'((?<![\w\"\$])\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1', tokens.Literal),
34
35 (r'\?', tokens.Name.Placeholder),
36 (r'%(\(\w+\))?s', tokens.Name.Placeholder),
37 (r'(?<!\w)[$:?]\w+', tokens.Name.Placeholder),
38
39 (r'\\\w+', tokens.Command),
40
41 # FIXME(andi): VALUES shouldn't be listed here
42 # see https://github.com/andialbrecht/sqlparse/pull/64
43 # AS and IN are special, it may be followed by a parenthesis, but
44 # are never functions, see issue183 and issue507
45 (r'(CASE|IN|VALUES|USING|FROM|AS)\b', tokens.Keyword),
46
47 (r'(@|##|#)[A-ZÀ-Ü]\w+', tokens.Name),
48
49 # see issue #39
50 # Spaces around period `schema . name` are valid identifier
51 # TODO: Spaces before period not implemented
52 (r'[A-ZÀ-Ü]\w*(?=\s*\.)', tokens.Name), # 'Name'.
53 # FIXME(atronah): never match,
54 # because `re.match` doesn't work with look-behind regexp feature
55 (r'(?<=\.)[A-ZÀ-Ü]\w*', tokens.Name), # .'Name'
56 (r'[A-ZÀ-Ü]\w*(?=\()', tokens.Name), # side effect: change kw to func
57 (r'-?0x[\dA-F]+', tokens.Number.Hexadecimal),
58 (r'-?\d+(\.\d+)?E-?\d+', tokens.Number.Float),
59 (r'(?![_A-ZÀ-Ü])-?(\d+(\.\d*)|\.\d+)(?![_A-ZÀ-Ü])',
60 tokens.Number.Float),
61 (r'(?![_A-ZÀ-Ü])-?\d+(?![_A-ZÀ-Ü])', tokens.Number.Integer),
62 (r"'(''|\\'|[^'])*'", tokens.String.Single),
63 # not a real string literal in ANSI SQL:
64 (r'"(""|\\"|[^"])*"', tokens.String.Symbol),
65 (r'(""|".*?[^\\]")', tokens.String.Symbol),
66 # sqlite names can be escaped with [square brackets]. left bracket
67 # cannot be preceded by word character or a right bracket --
68 # otherwise it's probably an array index
69 (r'(?<![\w\])])(\[[^\]\[]+\])', tokens.Name),
70 (r'((LEFT\s+|RIGHT\s+|FULL\s+)?(INNER\s+|OUTER\s+|STRAIGHT\s+)?'
71 r'|(CROSS\s+|NATURAL\s+)?)?JOIN\b', tokens.Keyword),
72 (r'END(\s+IF|\s+LOOP|\s+WHILE)?\b', tokens.Keyword),
73 (r'NOT\s+NULL\b', tokens.Keyword),
74 (r'(ASC|DESC)(\s+NULLS\s+(FIRST|LAST))?\b', tokens.Keyword.Order),
75 (r'(ASC|DESC)\b', tokens.Keyword.Order),
76 (r'NULLS\s+(FIRST|LAST)\b', tokens.Keyword.Order),
77 (r'UNION\s+ALL\b', tokens.Keyword),
78 (r'CREATE(\s+OR\s+REPLACE)?\b', tokens.Keyword.DDL),
79 (r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin),
80 (r'GROUP\s+BY\b', tokens.Keyword),
81 (r'ORDER\s+BY\b', tokens.Keyword),
82 (r'PRIMARY\s+KEY\b', tokens.Keyword),
83 (r'HANDLER\s+FOR\b', tokens.Keyword),
84 (r'GO(\s\d+)\b', tokens.Keyword),
85 (r'(LATERAL\s+VIEW\s+)'
86 r'(EXPLODE|INLINE|PARSE_URL_TUPLE|POSEXPLODE|STACK)\b',
87 tokens.Keyword),
88 (r"(AT|WITH')\s+TIME\s+ZONE\s+'[^']+'", tokens.Keyword.TZCast),
89 (r'(NOT\s+)?(LIKE|ILIKE|RLIKE)\b', tokens.Operator.Comparison),
90 (r'(NOT\s+)?(REGEXP)\b', tokens.Operator.Comparison),
91 # Check for keywords, also returns tokens.Name if regex matches
92 # but the match isn't a keyword.
93 (r'\w[$#\w]*', PROCESS_AS_KEYWORD),
94 (r'[;:()\[\],\.]', tokens.Punctuation),
95 # JSON operators
96 (r'(\->>?|#>>?|@>|<@|\?\|?|\?&|\-|#\-)', tokens.Operator),
97 (r'[<>=~!]+', tokens.Operator.Comparison),
98 (r'[+/@#%^&|^-]+', tokens.Operator),
99]
100
101KEYWORDS = {
102 'ABORT': tokens.Keyword,
103 'ABS': tokens.Keyword,
104 'ABSOLUTE': tokens.Keyword,
105 'ACCESS': tokens.Keyword,
106 'ADA': tokens.Keyword,
107 'ADD': tokens.Keyword,
108 'ADMIN': tokens.Keyword,
109 'AFTER': tokens.Keyword,
110 'AGGREGATE': tokens.Keyword,
111 'ALIAS': tokens.Keyword,
112 'ALL': tokens.Keyword,
113 'ALLOCATE': tokens.Keyword,
114 'ANALYSE': tokens.Keyword,
115 'ANALYZE': tokens.Keyword,
116 'ANY': tokens.Keyword,
117 'ARRAYLEN': tokens.Keyword,
118 'ARE': tokens.Keyword,
119 'ASENSITIVE': tokens.Keyword,
120 'ASSERTION': tokens.Keyword,
121 'ASSIGNMENT': tokens.Keyword,
122 'ASYMMETRIC': tokens.Keyword,
123 'AT': tokens.Keyword,
124 'ATOMIC': tokens.Keyword,
125 'AUDIT': tokens.Keyword,
126 'AUTHORIZATION': tokens.Keyword,
127 'AUTO_INCREMENT': tokens.Keyword,
128 'AVG': tokens.Keyword,
129
130 'BACKWARD': tokens.Keyword,
131 'BEFORE': tokens.Keyword,
132 'BEGIN': tokens.Keyword,
133 'BETWEEN': tokens.Keyword,
134 'BITVAR': tokens.Keyword,
135 'BIT_LENGTH': tokens.Keyword,
136 'BOTH': tokens.Keyword,
137 'BREADTH': tokens.Keyword,
138
139 # 'C': tokens.Keyword, # most likely this is an alias
140 'CACHE': tokens.Keyword,
141 'CALL': tokens.Keyword,
142 'CALLED': tokens.Keyword,
143 'CARDINALITY': tokens.Keyword,
144 'CASCADE': tokens.Keyword,
145 'CASCADED': tokens.Keyword,
146 'CAST': tokens.Keyword,
147 'CATALOG': tokens.Keyword,
148 'CATALOG_NAME': tokens.Keyword,
149 'CHAIN': tokens.Keyword,
150 'CHARACTERISTICS': tokens.Keyword,
151 'CHARACTER_LENGTH': tokens.Keyword,
152 'CHARACTER_SET_CATALOG': tokens.Keyword,
153 'CHARACTER_SET_NAME': tokens.Keyword,
154 'CHARACTER_SET_SCHEMA': tokens.Keyword,
155 'CHAR_LENGTH': tokens.Keyword,
156 'CHARSET': tokens.Keyword,
157 'CHECK': tokens.Keyword,
158 'CHECKED': tokens.Keyword,
159 'CHECKPOINT': tokens.Keyword,
160 'CLASS': tokens.Keyword,
161 'CLASS_ORIGIN': tokens.Keyword,
162 'CLOB': tokens.Keyword,
163 'CLOSE': tokens.Keyword,
164 'CLUSTER': tokens.Keyword,
165 'COALESCE': tokens.Keyword,
166 'COBOL': tokens.Keyword,
167 'COLLATE': tokens.Keyword,
168 'COLLATION': tokens.Keyword,
169 'COLLATION_CATALOG': tokens.Keyword,
170 'COLLATION_NAME': tokens.Keyword,
171 'COLLATION_SCHEMA': tokens.Keyword,
172 'COLLECT': tokens.Keyword,
173 'COLUMN': tokens.Keyword,
174 'COLUMN_NAME': tokens.Keyword,
175 'COMPRESS': tokens.Keyword,
176 'COMMAND_FUNCTION': tokens.Keyword,
177 'COMMAND_FUNCTION_CODE': tokens.Keyword,
178 'COMMENT': tokens.Keyword,
179 'COMMIT': tokens.Keyword.DML,
180 'COMMITTED': tokens.Keyword,
181 'COMPLETION': tokens.Keyword,
182 'CONCURRENTLY': tokens.Keyword,
183 'CONDITION_NUMBER': tokens.Keyword,
184 'CONNECT': tokens.Keyword,
185 'CONNECTION': tokens.Keyword,
186 'CONNECTION_NAME': tokens.Keyword,
187 'CONSTRAINT': tokens.Keyword,
188 'CONSTRAINTS': tokens.Keyword,
189 'CONSTRAINT_CATALOG': tokens.Keyword,
190 'CONSTRAINT_NAME': tokens.Keyword,
191 'CONSTRAINT_SCHEMA': tokens.Keyword,
192 'CONSTRUCTOR': tokens.Keyword,
193 'CONTAINS': tokens.Keyword,
194 'CONTINUE': tokens.Keyword,
195 'CONVERSION': tokens.Keyword,
196 'CONVERT': tokens.Keyword,
197 'COPY': tokens.Keyword,
198 'CORRESPONDING': tokens.Keyword,
199 'COUNT': tokens.Keyword,
200 'CREATEDB': tokens.Keyword,
201 'CREATEUSER': tokens.Keyword,
202 'CROSS': tokens.Keyword,
203 'CUBE': tokens.Keyword,
204 'CURRENT': tokens.Keyword,
205 'CURRENT_DATE': tokens.Keyword,
206 'CURRENT_PATH': tokens.Keyword,
207 'CURRENT_ROLE': tokens.Keyword,
208 'CURRENT_TIME': tokens.Keyword,
209 'CURRENT_TIMESTAMP': tokens.Keyword,
210 'CURRENT_USER': tokens.Keyword,
211 'CURSOR': tokens.Keyword,
212 'CURSOR_NAME': tokens.Keyword,
213 'CYCLE': tokens.Keyword,
214
215 'DATA': tokens.Keyword,
216 'DATABASE': tokens.Keyword,
217 'DATETIME_INTERVAL_CODE': tokens.Keyword,
218 'DATETIME_INTERVAL_PRECISION': tokens.Keyword,
219 'DAY': tokens.Keyword,
220 'DEALLOCATE': tokens.Keyword,
221 'DECLARE': tokens.Keyword,
222 'DEFAULT': tokens.Keyword,
223 'DEFAULTS': tokens.Keyword,
224 'DEFERRABLE': tokens.Keyword,
225 'DEFERRED': tokens.Keyword,
226 'DEFINED': tokens.Keyword,
227 'DEFINER': tokens.Keyword,
228 'DELIMITER': tokens.Keyword,
229 'DELIMITERS': tokens.Keyword,
230 'DEREF': tokens.Keyword,
231 'DESCRIBE': tokens.Keyword,
232 'DESCRIPTOR': tokens.Keyword,
233 'DESTROY': tokens.Keyword,
234 'DESTRUCTOR': tokens.Keyword,
235 'DETERMINISTIC': tokens.Keyword,
236 'DIAGNOSTICS': tokens.Keyword,
237 'DICTIONARY': tokens.Keyword,
238 'DISABLE': tokens.Keyword,
239 'DISCONNECT': tokens.Keyword,
240 'DISPATCH': tokens.Keyword,
241 'DIV': tokens.Operator,
242 'DO': tokens.Keyword,
243 'DOMAIN': tokens.Keyword,
244 'DYNAMIC': tokens.Keyword,
245 'DYNAMIC_FUNCTION': tokens.Keyword,
246 'DYNAMIC_FUNCTION_CODE': tokens.Keyword,
247
248 'EACH': tokens.Keyword,
249 'ENABLE': tokens.Keyword,
250 'ENCODING': tokens.Keyword,
251 'ENCRYPTED': tokens.Keyword,
252 'END-EXEC': tokens.Keyword,
253 'ENGINE': tokens.Keyword,
254 'EQUALS': tokens.Keyword,
255 'ESCAPE': tokens.Keyword,
256 'EVERY': tokens.Keyword,
257 'EXCEPT': tokens.Keyword,
258 'EXCEPTION': tokens.Keyword,
259 'EXCLUDING': tokens.Keyword,
260 'EXCLUSIVE': tokens.Keyword,
261 'EXEC': tokens.Keyword,
262 'EXECUTE': tokens.Keyword,
263 'EXISTING': tokens.Keyword,
264 'EXISTS': tokens.Keyword,
265 'EXPLAIN': tokens.Keyword,
266 'EXTERNAL': tokens.Keyword,
267 'EXTRACT': tokens.Keyword,
268
269 'FALSE': tokens.Keyword,
270 'FETCH': tokens.Keyword,
271 'FILE': tokens.Keyword,
272 'FINAL': tokens.Keyword,
273 'FIRST': tokens.Keyword,
274 'FORCE': tokens.Keyword,
275 'FOREACH': tokens.Keyword,
276 'FOREIGN': tokens.Keyword,
277 'FORTRAN': tokens.Keyword,
278 'FORWARD': tokens.Keyword,
279 'FOUND': tokens.Keyword,
280 'FREE': tokens.Keyword,
281 'FREEZE': tokens.Keyword,
282 'FULL': tokens.Keyword,
283 'FUNCTION': tokens.Keyword,
284
285 # 'G': tokens.Keyword,
286 'GENERAL': tokens.Keyword,
287 'GENERATED': tokens.Keyword,
288 'GET': tokens.Keyword,
289 'GLOBAL': tokens.Keyword,
290 'GO': tokens.Keyword,
291 'GOTO': tokens.Keyword,
292 'GRANTED': tokens.Keyword,
293 'GROUPING': tokens.Keyword,
294
295 'HAVING': tokens.Keyword,
296 'HIERARCHY': tokens.Keyword,
297 'HOLD': tokens.Keyword,
298 'HOUR': tokens.Keyword,
299 'HOST': tokens.Keyword,
300
301 'IDENTIFIED': tokens.Keyword,
302 'IDENTITY': tokens.Keyword,
303 'IGNORE': tokens.Keyword,
304 'ILIKE': tokens.Keyword,
305 'IMMEDIATE': tokens.Keyword,
306 'IMMUTABLE': tokens.Keyword,
307
308 'IMPLEMENTATION': tokens.Keyword,
309 'IMPLICIT': tokens.Keyword,
310 'INCLUDING': tokens.Keyword,
311 'INCREMENT': tokens.Keyword,
312 'INDEX': tokens.Keyword,
313
314 'INDICATOR': tokens.Keyword,
315 'INFIX': tokens.Keyword,
316 'INHERITS': tokens.Keyword,
317 'INITIAL': tokens.Keyword,
318 'INITIALIZE': tokens.Keyword,
319 'INITIALLY': tokens.Keyword,
320 'INOUT': tokens.Keyword,
321 'INPUT': tokens.Keyword,
322 'INSENSITIVE': tokens.Keyword,
323 'INSTANTIABLE': tokens.Keyword,
324 'INSTEAD': tokens.Keyword,
325 'INTERSECT': tokens.Keyword,
326 'INTO': tokens.Keyword,
327 'INVOKER': tokens.Keyword,
328 'IS': tokens.Keyword,
329 'ISNULL': tokens.Keyword,
330 'ISOLATION': tokens.Keyword,
331 'ITERATE': tokens.Keyword,
332
333 # 'K': tokens.Keyword,
334 'KEY': tokens.Keyword,
335 'KEY_MEMBER': tokens.Keyword,
336 'KEY_TYPE': tokens.Keyword,
337
338 'LANCOMPILER': tokens.Keyword,
339 'LANGUAGE': tokens.Keyword,
340 'LARGE': tokens.Keyword,
341 'LAST': tokens.Keyword,
342 'LATERAL': tokens.Keyword,
343 'LEADING': tokens.Keyword,
344 'LENGTH': tokens.Keyword,
345 'LESS': tokens.Keyword,
346 'LEVEL': tokens.Keyword,
347 'LIMIT': tokens.Keyword,
348 'LISTEN': tokens.Keyword,
349 'LOAD': tokens.Keyword,
350 'LOCAL': tokens.Keyword,
351 'LOCALTIME': tokens.Keyword,
352 'LOCALTIMESTAMP': tokens.Keyword,
353 'LOCATION': tokens.Keyword,
354 'LOCATOR': tokens.Keyword,
355 'LOCK': tokens.Keyword,
356 'LOWER': tokens.Keyword,
357
358 # 'M': tokens.Keyword,
359 'MAP': tokens.Keyword,
360 'MATCH': tokens.Keyword,
361 'MAXEXTENTS': tokens.Keyword,
362 'MAXVALUE': tokens.Keyword,
363 'MESSAGE_LENGTH': tokens.Keyword,
364 'MESSAGE_OCTET_LENGTH': tokens.Keyword,
365 'MESSAGE_TEXT': tokens.Keyword,
366 'METHOD': tokens.Keyword,
367 'MINUTE': tokens.Keyword,
368 'MINUS': tokens.Keyword,
369 'MINVALUE': tokens.Keyword,
370 'MOD': tokens.Keyword,
371 'MODE': tokens.Keyword,
372 'MODIFIES': tokens.Keyword,
373 'MODIFY': tokens.Keyword,
374 'MONTH': tokens.Keyword,
375 'MORE': tokens.Keyword,
376 'MOVE': tokens.Keyword,
377 'MUMPS': tokens.Keyword,
378
379 'NAMES': tokens.Keyword,
380 'NATIONAL': tokens.Keyword,
381 'NATURAL': tokens.Keyword,
382 'NCHAR': tokens.Keyword,
383 'NCLOB': tokens.Keyword,
384 'NEW': tokens.Keyword,
385 'NEXT': tokens.Keyword,
386 'NO': tokens.Keyword,
387 'NOAUDIT': tokens.Keyword,
388 'NOCOMPRESS': tokens.Keyword,
389 'NOCREATEDB': tokens.Keyword,
390 'NOCREATEUSER': tokens.Keyword,
391 'NONE': tokens.Keyword,
392 'NOT': tokens.Keyword,
393 'NOTFOUND': tokens.Keyword,
394 'NOTHING': tokens.Keyword,
395 'NOTIFY': tokens.Keyword,
396 'NOTNULL': tokens.Keyword,
397 'NOWAIT': tokens.Keyword,
398 'NULL': tokens.Keyword,
399 'NULLABLE': tokens.Keyword,
400 'NULLIF': tokens.Keyword,
401
402 'OBJECT': tokens.Keyword,
403 'OCTET_LENGTH': tokens.Keyword,
404 'OF': tokens.Keyword,
405 'OFF': tokens.Keyword,
406 'OFFLINE': tokens.Keyword,
407 'OFFSET': tokens.Keyword,
408 'OIDS': tokens.Keyword,
409 'OLD': tokens.Keyword,
410 'ONLINE': tokens.Keyword,
411 'ONLY': tokens.Keyword,
412 'OPEN': tokens.Keyword,
413 'OPERATION': tokens.Keyword,
414 'OPERATOR': tokens.Keyword,
415 'OPTION': tokens.Keyword,
416 'OPTIONS': tokens.Keyword,
417 'ORDINALITY': tokens.Keyword,
418 'OUT': tokens.Keyword,
419 'OUTPUT': tokens.Keyword,
420 'OVERLAPS': tokens.Keyword,
421 'OVERLAY': tokens.Keyword,
422 'OVERRIDING': tokens.Keyword,
423 'OWNER': tokens.Keyword,
424
425 'QUARTER': tokens.Keyword,
426
427 'PAD': tokens.Keyword,
428 'PARAMETER': tokens.Keyword,
429 'PARAMETERS': tokens.Keyword,
430 'PARAMETER_MODE': tokens.Keyword,
431 'PARAMETER_NAME': tokens.Keyword,
432 'PARAMETER_ORDINAL_POSITION': tokens.Keyword,
433 'PARAMETER_SPECIFIC_CATALOG': tokens.Keyword,
434 'PARAMETER_SPECIFIC_NAME': tokens.Keyword,
435 'PARAMETER_SPECIFIC_SCHEMA': tokens.Keyword,
436 'PARTIAL': tokens.Keyword,
437 'PASCAL': tokens.Keyword,
438 'PCTFREE': tokens.Keyword,
439 'PENDANT': tokens.Keyword,
440 'PLACING': tokens.Keyword,
441 'PLI': tokens.Keyword,
442 'POSITION': tokens.Keyword,
443 'POSTFIX': tokens.Keyword,
444 'PRECISION': tokens.Keyword,
445 'PREFIX': tokens.Keyword,
446 'PREORDER': tokens.Keyword,
447 'PREPARE': tokens.Keyword,
448 'PRESERVE': tokens.Keyword,
449 'PRIMARY': tokens.Keyword,
450 'PRIOR': tokens.Keyword,
451 'PRIVILEGES': tokens.Keyword,
452 'PROCEDURAL': tokens.Keyword,
453 'PROCEDURE': tokens.Keyword,
454 'PUBLIC': tokens.Keyword,
455
456 'RAISE': tokens.Keyword,
457 'RAW': tokens.Keyword,
458 'READ': tokens.Keyword,
459 'READS': tokens.Keyword,
460 'RECHECK': tokens.Keyword,
461 'RECURSIVE': tokens.Keyword,
462 'REF': tokens.Keyword,
463 'REFERENCES': tokens.Keyword,
464 'REFERENCING': tokens.Keyword,
465 'REINDEX': tokens.Keyword,
466 'RELATIVE': tokens.Keyword,
467 'RENAME': tokens.Keyword,
468 'REPEATABLE': tokens.Keyword,
469 'RESET': tokens.Keyword,
470 'RESOURCE': tokens.Keyword,
471 'RESTART': tokens.Keyword,
472 'RESTRICT': tokens.Keyword,
473 'RESULT': tokens.Keyword,
474 'RETURN': tokens.Keyword,
475 'RETURNED_LENGTH': tokens.Keyword,
476 'RETURNED_OCTET_LENGTH': tokens.Keyword,
477 'RETURNED_SQLSTATE': tokens.Keyword,
478 'RETURNING': tokens.Keyword,
479 'RETURNS': tokens.Keyword,
480 'RIGHT': tokens.Keyword,
481 'ROLE': tokens.Keyword,
482 'ROLLBACK': tokens.Keyword.DML,
483 'ROLLUP': tokens.Keyword,
484 'ROUTINE': tokens.Keyword,
485 'ROUTINE_CATALOG': tokens.Keyword,
486 'ROUTINE_NAME': tokens.Keyword,
487 'ROUTINE_SCHEMA': tokens.Keyword,
488 'ROWS': tokens.Keyword,
489 'ROW_COUNT': tokens.Keyword,
490 'RULE': tokens.Keyword,
491
492 'SAVE_POINT': tokens.Keyword,
493 'SCALE': tokens.Keyword,
494 'SCHEMA': tokens.Keyword,
495 'SCHEMA_NAME': tokens.Keyword,
496 'SCOPE': tokens.Keyword,
497 'SCROLL': tokens.Keyword,
498 'SEARCH': tokens.Keyword,
499 'SECOND': tokens.Keyword,
500 'SECURITY': tokens.Keyword,
501 'SELF': tokens.Keyword,
502 'SENSITIVE': tokens.Keyword,
503 'SEQUENCE': tokens.Keyword,
504 'SERIALIZABLE': tokens.Keyword,
505 'SERVER_NAME': tokens.Keyword,
506 'SESSION': tokens.Keyword,
507 'SESSION_USER': tokens.Keyword,
508 'SETOF': tokens.Keyword,
509 'SETS': tokens.Keyword,
510 'SHARE': tokens.Keyword,
511 'SHOW': tokens.Keyword,
512 'SIMILAR': tokens.Keyword,
513 'SIMPLE': tokens.Keyword,
514 'SIZE': tokens.Keyword,
515 'SOME': tokens.Keyword,
516 'SOURCE': tokens.Keyword,
517 'SPACE': tokens.Keyword,
518 'SPECIFIC': tokens.Keyword,
519 'SPECIFICTYPE': tokens.Keyword,
520 'SPECIFIC_NAME': tokens.Keyword,
521 'SQL': tokens.Keyword,
522 'SQLBUF': tokens.Keyword,
523 'SQLCODE': tokens.Keyword,
524 'SQLERROR': tokens.Keyword,
525 'SQLEXCEPTION': tokens.Keyword,
526 'SQLSTATE': tokens.Keyword,
527 'SQLWARNING': tokens.Keyword,
528 'STABLE': tokens.Keyword,
529 'START': tokens.Keyword.DML,
530 # 'STATE': tokens.Keyword,
531 'STATEMENT': tokens.Keyword,
532 'STATIC': tokens.Keyword,
533 'STATISTICS': tokens.Keyword,
534 'STDIN': tokens.Keyword,
535 'STDOUT': tokens.Keyword,
536 'STORAGE': tokens.Keyword,
537 'STRICT': tokens.Keyword,
538 'STRUCTURE': tokens.Keyword,
539 'STYPE': tokens.Keyword,
540 'SUBCLASS_ORIGIN': tokens.Keyword,
541 'SUBLIST': tokens.Keyword,
542 'SUBSTRING': tokens.Keyword,
543 'SUCCESSFUL': tokens.Keyword,
544 'SUM': tokens.Keyword,
545 'SYMMETRIC': tokens.Keyword,
546 'SYNONYM': tokens.Keyword,
547 'SYSID': tokens.Keyword,
548 'SYSTEM': tokens.Keyword,
549 'SYSTEM_USER': tokens.Keyword,
550
551 'TABLE': tokens.Keyword,
552 'TABLE_NAME': tokens.Keyword,
553 'TEMP': tokens.Keyword,
554 'TEMPLATE': tokens.Keyword,
555 'TEMPORARY': tokens.Keyword,
556 'TERMINATE': tokens.Keyword,
557 'THAN': tokens.Keyword,
558 'TIMESTAMP': tokens.Keyword,
559 'TIMEZONE_HOUR': tokens.Keyword,
560 'TIMEZONE_MINUTE': tokens.Keyword,
561 'TO': tokens.Keyword,
562 'TOAST': tokens.Keyword,
563 'TRAILING': tokens.Keyword,
564 'TRANSATION': tokens.Keyword,
565 'TRANSACTIONS_COMMITTED': tokens.Keyword,
566 'TRANSACTIONS_ROLLED_BACK': tokens.Keyword,
567 'TRANSATION_ACTIVE': tokens.Keyword,
568 'TRANSFORM': tokens.Keyword,
569 'TRANSFORMS': tokens.Keyword,
570 'TRANSLATE': tokens.Keyword,
571 'TRANSLATION': tokens.Keyword,
572 'TREAT': tokens.Keyword,
573 'TRIGGER': tokens.Keyword,
574 'TRIGGER_CATALOG': tokens.Keyword,
575 'TRIGGER_NAME': tokens.Keyword,
576 'TRIGGER_SCHEMA': tokens.Keyword,
577 'TRIM': tokens.Keyword,
578 'TRUE': tokens.Keyword,
579 'TRUSTED': tokens.Keyword,
580 'TYPE': tokens.Keyword,
581
582 'UID': tokens.Keyword,
583 'UNCOMMITTED': tokens.Keyword,
584 'UNDER': tokens.Keyword,
585 'UNENCRYPTED': tokens.Keyword,
586 'UNION': tokens.Keyword,
587 'UNIQUE': tokens.Keyword,
588 'UNKNOWN': tokens.Keyword,
589 'UNLISTEN': tokens.Keyword,
590 'UNNAMED': tokens.Keyword,
591 'UNNEST': tokens.Keyword,
592 'UNTIL': tokens.Keyword,
593 'UPPER': tokens.Keyword,
594 'USAGE': tokens.Keyword,
595 'USE': tokens.Keyword,
596 'USER': tokens.Keyword,
597 'USER_DEFINED_TYPE_CATALOG': tokens.Keyword,
598 'USER_DEFINED_TYPE_NAME': tokens.Keyword,
599 'USER_DEFINED_TYPE_SCHEMA': tokens.Keyword,
600 'USING': tokens.Keyword,
601
602 'VACUUM': tokens.Keyword,
603 'VALID': tokens.Keyword,
604 'VALIDATE': tokens.Keyword,
605 'VALIDATOR': tokens.Keyword,
606 'VALUES': tokens.Keyword,
607 'VARIABLE': tokens.Keyword,
608 'VERBOSE': tokens.Keyword,
609 'VERSION': tokens.Keyword,
610 'VIEW': tokens.Keyword,
611 'VOLATILE': tokens.Keyword,
612
613 'WEEK': tokens.Keyword,
614 'WHENEVER': tokens.Keyword,
615 'WITH': tokens.Keyword.CTE,
616 'WITHOUT': tokens.Keyword,
617 'WORK': tokens.Keyword,
618 'WRITE': tokens.Keyword,
619
620 'YEAR': tokens.Keyword,
621
622 'ZONE': tokens.Keyword,
623
624 # Name.Builtin
625 'ARRAY': tokens.Name.Builtin,
626 'BIGINT': tokens.Name.Builtin,
627 'BINARY': tokens.Name.Builtin,
628 'BIT': tokens.Name.Builtin,
629 'BLOB': tokens.Name.Builtin,
630 'BOOLEAN': tokens.Name.Builtin,
631 'CHAR': tokens.Name.Builtin,
632 'CHARACTER': tokens.Name.Builtin,
633 'DATE': tokens.Name.Builtin,
634 'DEC': tokens.Name.Builtin,
635 'DECIMAL': tokens.Name.Builtin,
636 'FILE_TYPE': tokens.Name.Builtin,
637 'FLOAT': tokens.Name.Builtin,
638 'INT': tokens.Name.Builtin,
639 'INT8': tokens.Name.Builtin,
640 'INTEGER': tokens.Name.Builtin,
641 'INTERVAL': tokens.Name.Builtin,
642 'LONG': tokens.Name.Builtin,
643 'NATURALN': tokens.Name.Builtin,
644 'NVARCHAR': tokens.Name.Builtin,
645 'NUMBER': tokens.Name.Builtin,
646 'NUMERIC': tokens.Name.Builtin,
647 'PLS_INTEGER': tokens.Name.Builtin,
648 'POSITIVE': tokens.Name.Builtin,
649 'POSITIVEN': tokens.Name.Builtin,
650 'REAL': tokens.Name.Builtin,
651 'ROWID': tokens.Name.Builtin,
652 'ROWLABEL': tokens.Name.Builtin,
653 'ROWNUM': tokens.Name.Builtin,
654 'SERIAL': tokens.Name.Builtin,
655 'SERIAL8': tokens.Name.Builtin,
656 'SIGNED': tokens.Name.Builtin,
657 'SIGNTYPE': tokens.Name.Builtin,
658 'SIMPLE_DOUBLE': tokens.Name.Builtin,
659 'SIMPLE_FLOAT': tokens.Name.Builtin,
660 'SIMPLE_INTEGER': tokens.Name.Builtin,
661 'SMALLINT': tokens.Name.Builtin,
662 'SYS_REFCURSOR': tokens.Name.Builtin,
663 'SYSDATE': tokens.Name,
664 'TEXT': tokens.Name.Builtin,
665 'TINYINT': tokens.Name.Builtin,
666 'UNSIGNED': tokens.Name.Builtin,
667 'UROWID': tokens.Name.Builtin,
668 'UTL_FILE': tokens.Name.Builtin,
669 'VARCHAR': tokens.Name.Builtin,
670 'VARCHAR2': tokens.Name.Builtin,
671 'VARYING': tokens.Name.Builtin,
672}
673
674KEYWORDS_COMMON = {
675 'SELECT': tokens.Keyword.DML,
676 'INSERT': tokens.Keyword.DML,
677 'DELETE': tokens.Keyword.DML,
678 'UPDATE': tokens.Keyword.DML,
679 'UPSERT': tokens.Keyword.DML,
680 'REPLACE': tokens.Keyword.DML,
681 'MERGE': tokens.Keyword.DML,
682 'DROP': tokens.Keyword.DDL,
683 'CREATE': tokens.Keyword.DDL,
684 'ALTER': tokens.Keyword.DDL,
685 'TRUNCATE': tokens.Keyword.DDL,
686 'GRANT': tokens.Keyword.DCL,
687 'REVOKE': tokens.Keyword.DCL,
688
689 'WHERE': tokens.Keyword,
690 'FROM': tokens.Keyword,
691 'INNER': tokens.Keyword,
692 'JOIN': tokens.Keyword,
693 'STRAIGHT_JOIN': tokens.Keyword,
694 'AND': tokens.Keyword,
695 'OR': tokens.Keyword,
696 'LIKE': tokens.Keyword,
697 'ON': tokens.Keyword,
698 'IN': tokens.Keyword,
699 'SET': tokens.Keyword,
700
701 'BY': tokens.Keyword,
702 'GROUP': tokens.Keyword,
703 'ORDER': tokens.Keyword,
704 'LEFT': tokens.Keyword,
705 'OUTER': tokens.Keyword,
706 'FULL': tokens.Keyword,
707
708 'IF': tokens.Keyword,
709 'END': tokens.Keyword,
710 'THEN': tokens.Keyword,
711 'LOOP': tokens.Keyword,
712 'AS': tokens.Keyword,
713 'ELSE': tokens.Keyword,
714 'FOR': tokens.Keyword,
715 'WHILE': tokens.Keyword,
716
717 'CASE': tokens.Keyword,
718 'WHEN': tokens.Keyword,
719 'MIN': tokens.Keyword,
720 'MAX': tokens.Keyword,
721 'DISTINCT': tokens.Keyword,
722}
723
724KEYWORDS_ORACLE = {
725 'ARCHIVE': tokens.Keyword,
726 'ARCHIVELOG': tokens.Keyword,
727
728 'BACKUP': tokens.Keyword,
729 'BECOME': tokens.Keyword,
730 'BLOCK': tokens.Keyword,
731 'BODY': tokens.Keyword,
732
733 'CANCEL': tokens.Keyword,
734 'CHANGE': tokens.Keyword,
735 'COMPILE': tokens.Keyword,
736 'CONTENTS': tokens.Keyword,
737 'CONTROLFILE': tokens.Keyword,
738
739 'DATAFILE': tokens.Keyword,
740 'DBA': tokens.Keyword,
741 'DISMOUNT': tokens.Keyword,
742 'DOUBLE': tokens.Keyword,
743 'DUMP': tokens.Keyword,
744
745 'ELSIF': tokens.Keyword,
746 'EVENTS': tokens.Keyword,
747 'EXCEPTIONS': tokens.Keyword,
748 'EXPLAIN': tokens.Keyword,
749 'EXTENT': tokens.Keyword,
750 'EXTERNALLY': tokens.Keyword,
751
752 'FLUSH': tokens.Keyword,
753 'FREELIST': tokens.Keyword,
754 'FREELISTS': tokens.Keyword,
755
756 # groups seems too common as table name
757 # 'GROUPS': tokens.Keyword,
758
759 'INDICATOR': tokens.Keyword,
760 'INITRANS': tokens.Keyword,
761 'INSTANCE': tokens.Keyword,
762
763 'LAYER': tokens.Keyword,
764 'LINK': tokens.Keyword,
765 'LISTS': tokens.Keyword,
766 'LOGFILE': tokens.Keyword,
767
768 'MANAGE': tokens.Keyword,
769 'MANUAL': tokens.Keyword,
770 'MAXDATAFILES': tokens.Keyword,
771 'MAXINSTANCES': tokens.Keyword,
772 'MAXLOGFILES': tokens.Keyword,
773 'MAXLOGHISTORY': tokens.Keyword,
774 'MAXLOGMEMBERS': tokens.Keyword,
775 'MAXTRANS': tokens.Keyword,
776 'MINEXTENTS': tokens.Keyword,
777 'MODULE': tokens.Keyword,
778 'MOUNT': tokens.Keyword,
779
780 'NOARCHIVELOG': tokens.Keyword,
781 'NOCACHE': tokens.Keyword,
782 'NOCYCLE': tokens.Keyword,
783 'NOMAXVALUE': tokens.Keyword,
784 'NOMINVALUE': tokens.Keyword,
785 'NOORDER': tokens.Keyword,
786 'NORESETLOGS': tokens.Keyword,
787 'NORMAL': tokens.Keyword,
788 'NOSORT': tokens.Keyword,
789
790 'OPTIMAL': tokens.Keyword,
791 'OWN': tokens.Keyword,
792
793 'PACKAGE': tokens.Keyword,
794 'PARALLEL': tokens.Keyword,
795 'PCTINCREASE': tokens.Keyword,
796 'PCTUSED': tokens.Keyword,
797 'PLAN': tokens.Keyword,
798 'PRIVATE': tokens.Keyword,
799 'PROFILE': tokens.Keyword,
800
801 'QUOTA': tokens.Keyword,
802
803 'RECOVER': tokens.Keyword,
804 'RESETLOGS': tokens.Keyword,
805 'RESTRICTED': tokens.Keyword,
806 'REUSE': tokens.Keyword,
807 'ROLES': tokens.Keyword,
808
809 'SAVEPOINT': tokens.Keyword,
810 'SCN': tokens.Keyword,
811 'SECTION': tokens.Keyword,
812 'SEGMENT': tokens.Keyword,
813 'SHARED': tokens.Keyword,
814 'SNAPSHOT': tokens.Keyword,
815 'SORT': tokens.Keyword,
816 'STATEMENT_ID': tokens.Keyword,
817 'STOP': tokens.Keyword,
818 'SWITCH': tokens.Keyword,
819
820 'TABLES': tokens.Keyword,
821 'TABLESPACE': tokens.Keyword,
822 'THREAD': tokens.Keyword,
823 'TIME': tokens.Keyword,
824 'TRACING': tokens.Keyword,
825 'TRANSACTION': tokens.Keyword,
826 'TRIGGERS': tokens.Keyword,
827
828 'UNLIMITED': tokens.Keyword,
829 'UNLOCK': tokens.Keyword,
830}
831
832# MySQL
833KEYWORDS_MYSQL = {
834 'ROW': tokens.Keyword,
835}
836
837# PostgreSQL Syntax
838KEYWORDS_PLPGSQL = {
839 'CONFLICT': tokens.Keyword,
840 'WINDOW': tokens.Keyword,
841 'PARTITION': tokens.Keyword,
842 'OVER': tokens.Keyword,
843 'PERFORM': tokens.Keyword,
844 'NOTICE': tokens.Keyword,
845 'PLPGSQL': tokens.Keyword,
846 'INHERIT': tokens.Keyword,
847 'INDEXES': tokens.Keyword,
848 'ON_ERROR_STOP': tokens.Keyword,
849 'EXTENSION': tokens.Keyword,
850
851 'BYTEA': tokens.Keyword,
852 'BIGSERIAL': tokens.Keyword,
853 'BIT VARYING': tokens.Keyword,
854 'BOX': tokens.Keyword,
855 'CHARACTER': tokens.Keyword,
856 'CHARACTER VARYING': tokens.Keyword,
857 'CIDR': tokens.Keyword,
858 'CIRCLE': tokens.Keyword,
859 'DOUBLE PRECISION': tokens.Keyword,
860 'INET': tokens.Keyword,
861 'JSON': tokens.Keyword,
862 'JSONB': tokens.Keyword,
863 'LINE': tokens.Keyword,
864 'LSEG': tokens.Keyword,
865 'MACADDR': tokens.Keyword,
866 'MONEY': tokens.Keyword,
867 'PATH': tokens.Keyword,
868 'PG_LSN': tokens.Keyword,
869 'POINT': tokens.Keyword,
870 'POLYGON': tokens.Keyword,
871 'SMALLSERIAL': tokens.Keyword,
872 'TSQUERY': tokens.Keyword,
873 'TSVECTOR': tokens.Keyword,
874 'TXID_SNAPSHOT': tokens.Keyword,
875 'UUID': tokens.Keyword,
876 'XML': tokens.Keyword,
877
878 'FOR': tokens.Keyword,
879 'IN': tokens.Keyword,
880 'LOOP': tokens.Keyword,
881}
882
883# Hive Syntax
884KEYWORDS_HQL = {
885 'EXPLODE': tokens.Keyword,
886 'DIRECTORY': tokens.Keyword,
887 'DISTRIBUTE': tokens.Keyword,
888 'INCLUDE': tokens.Keyword,
889 'LOCATE': tokens.Keyword,
890 'OVERWRITE': tokens.Keyword,
891 'POSEXPLODE': tokens.Keyword,
892
893 'ARRAY_CONTAINS': tokens.Keyword,
894 'CMP': tokens.Keyword,
895 'COLLECT_LIST': tokens.Keyword,
896 'CONCAT': tokens.Keyword,
897 'CONDITION': tokens.Keyword,
898 'DATE_ADD': tokens.Keyword,
899 'DATE_SUB': tokens.Keyword,
900 'DECODE': tokens.Keyword,
901 'DBMS_OUTPUT': tokens.Keyword,
902 'ELEMENTS': tokens.Keyword,
903 'EXCHANGE': tokens.Keyword,
904 'EXTENDED': tokens.Keyword,
905 'FLOOR': tokens.Keyword,
906 'FOLLOWING': tokens.Keyword,
907 'FROM_UNIXTIME': tokens.Keyword,
908 'FTP': tokens.Keyword,
909 'HOUR': tokens.Keyword,
910 'INLINE': tokens.Keyword,
911 'INSTR': tokens.Keyword,
912 'LEN': tokens.Keyword,
913 'MAP': tokens.Name.Builtin,
914 'MAXELEMENT': tokens.Keyword,
915 'MAXINDEX': tokens.Keyword,
916 'MAX_PART_DATE': tokens.Keyword,
917 'MAX_PART_INT': tokens.Keyword,
918 'MAX_PART_STRING': tokens.Keyword,
919 'MINELEMENT': tokens.Keyword,
920 'MININDEX': tokens.Keyword,
921 'MIN_PART_DATE': tokens.Keyword,
922 'MIN_PART_INT': tokens.Keyword,
923 'MIN_PART_STRING': tokens.Keyword,
924 'NOW': tokens.Keyword,
925 'NVL': tokens.Keyword,
926 'NVL2': tokens.Keyword,
927 'PARSE_URL_TUPLE': tokens.Keyword,
928 'PART_LOC': tokens.Keyword,
929 'PART_COUNT': tokens.Keyword,
930 'PART_COUNT_BY': tokens.Keyword,
931 'PRINT': tokens.Keyword,
932 'PUT_LINE': tokens.Keyword,
933 'RANGE': tokens.Keyword,
934 'REDUCE': tokens.Keyword,
935 'REGEXP_REPLACE': tokens.Keyword,
936 'RESIGNAL': tokens.Keyword,
937 'RTRIM': tokens.Keyword,
938 'SIGN': tokens.Keyword,
939 'SIGNAL': tokens.Keyword,
940 'SIN': tokens.Keyword,
941 'SPLIT': tokens.Keyword,
942 'SQRT': tokens.Keyword,
943 'STACK': tokens.Keyword,
944 'STR': tokens.Keyword,
945 'STRING': tokens.Name.Builtin,
946 'STRUCT': tokens.Name.Builtin,
947 'SUBSTR': tokens.Keyword,
948 'SUMMARY': tokens.Keyword,
949 'TBLPROPERTIES': tokens.Keyword,
950 'TIMESTAMP': tokens.Name.Builtin,
951 'TIMESTAMP_ISO': tokens.Keyword,
952 'TO_CHAR': tokens.Keyword,
953 'TO_DATE': tokens.Keyword,
954 'TO_TIMESTAMP': tokens.Keyword,
955 'TRUNC': tokens.Keyword,
956 'UNBOUNDED': tokens.Keyword,
957 'UNIQUEJOIN': tokens.Keyword,
958 'UNIX_TIMESTAMP': tokens.Keyword,
959 'UTC_TIMESTAMP': tokens.Keyword,
960 'VIEWS': tokens.Keyword,
961
962 'EXIT': tokens.Keyword,
963 'BREAK': tokens.Keyword,
964 'LEAVE': tokens.Keyword,
965}
966
967
968KEYWORDS_MSACCESS = {
969 'DISTINCTROW': tokens.Keyword,
970}
971
972
973KEYWORDS_SNOWFLAKE = {
974 'ACCOUNT': tokens.Keyword,
975 'GSCLUSTER': tokens.Keyword,
976 'ISSUE': tokens.Keyword,
977 'ORGANIZATION': tokens.Keyword,
978 'PIVOT': tokens.Keyword,
979 'QUALIFY': tokens.Keyword,
980 'REGEXP': tokens.Keyword,
981 'RLIKE': tokens.Keyword,
982 'SAMPLE': tokens.Keyword,
983 'TRY_CAST': tokens.Keyword,
984 'UNPIVOT': tokens.Keyword,
985
986 'VARIANT': tokens.Name.Builtin,
987}
988
989
990KEYWORDS_BIGQUERY = {
991 'ASSERT_ROWS_MODIFIED': tokens.Keyword,
992 'DEFINE': tokens.Keyword,
993 'ENUM': tokens.Keyword,
994 'HASH': tokens.Keyword,
995 'LOOKUP': tokens.Keyword,
996 'PRECEDING': tokens.Keyword,
997 'PROTO': tokens.Keyword,
998 'RESPECT': tokens.Keyword,
999 'TABLESAMPLE': tokens.Keyword,
1000
1001 'BIGNUMERIC': tokens.Name.Builtin,
1002}