forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgresql.ts
More file actions
1345 lines (756 loc) · 32.8 KB
/
postgresql.ts
File metadata and controls
1345 lines (756 loc) · 32.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔
⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔ THIS FILE HAS BEEN AUTO-GENERATED DO NOT EDIT IT ! ⛔⛔⛔⛔⛔⛔⛔⛔
⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔⛔
*/
export type start = multiple_stmt | cmd_stmt | crud_stmt;
export type cmd_stmt = drop_stmt | create_stmt | truncate_stmt | rename_stmt | call_stmt | use_stmt | alter_stmt | set_stmt | lock_stmt;
export type create_stmt = create_table_stmt | create_constraint_trigger | create_extension_stmt | create_index_stmt | create_sequence | create_db_stmt;
export type alter_stmt = alter_table_stmt;
export type crud_stmt = union_stmt | update_stmt | replace_insert_stmt | insert_no_columns_stmt | delete_stmt | cmd_stmt | proc_stmts;
// is in reality: { tableList: any[]; columnList: any[]; ast: T; }
export type AstStatement<T> = T;
export type multiple_stmt = AstStatement<crud_stmt[]>;
export interface union_stmt_node extends select_stmt_node {
_next: union_stmt_node;
union: 'union' | 'union all';
}
export type union_stmt = AstStatement<union_stmt_node>;
export type nameOrLiteral = literal_string | { type: 'same', value: string; };
export type create_extension_stmt = {
type: 'create';
keyword: 'extension';
if_not_exists?: 'if not exists';
extension: nameOrLiteral;
with: 'with';
schema: nameOrLiteral;
version: nameOrLiteral;
from: nameOrLiteral;
};
export type create_db_definition = create_option_character_set[];
export type create_db_stmt = {
type: 'create',
keyword: 'database',
if_not_exists?: 'if not exists',
database: string,
create_definition?: create_db_definition
}
export type create_db_stmt = AstStatement<create_db_stmt>;
export type create_table_stmt_node = create_table_stmt_node_simple | create_table_stmt_node_like;
export interface create_table_stmt_node_base {
type: 'create';
keyword: 'table';
temporary?: 'temporary';
if_not_exists?: 'if not exists';
table: table_ref_list;
}
export interface create_table_stmt_node_simple extends create_table_stmt_node_base{
ignore_replace?: 'ignore' | 'replace';
as?: 'as';
query_expr?: union_stmt_node;
create_definition?: create_table_definition;
table_options?: table_options;
}
export interface create_table_stmt_node_like extends create_table_stmt_node_base{
like: create_like_table;
}
export type create_table_stmt = AstStatement<create_table_stmt_node> | AstStatement<create_table_stmt_node>;;
export type create_sequence_stmt = {
type: 'create',
keyword: 'sequence',
temporary?: 'temporary' | 'temp',
if_not_exists?: 'if not exists',
table: table_ref_list,
create_definition?: create_sequence_definition_list
}
export type create_sequence = AstStatement<create_sequence_stmt>;
export type sequence_definition = { "resource": "sequence", prefix?: string,value: literal | column_ref }
export type sequence_definition_increment = sequence_definition;
export type sequence_definition_minval = sequence_definition;
export type sequence_definition_maxval = sequence_definition;
export type sequence_definition_start = sequence_definition;
export type sequence_definition_cache = sequence_definition;
export type sequence_definition_cycle = sequence_definition;
export type sequence_definition_owned = sequence_definition;
export type create_sequence_definition = sequence_definition_increment | sequence_definition_minval | sequence_definition_maxval | sequence_definition_start | sequence_definition_cache | sequence_definition_cycle | sequence_definition_owned;
export type create_sequence_definition_list = create_sequence_definition[];
export interface create_index_stmt_node {
type: 'create';
index_type?: 'unique';
keyword: 'index';
concurrently?: 'concurrently';
index: string;
on_kw: string;
table: table_name;
index_using?: index_type;
index_columns: column_order[];
with?: index_option[];
with_before_where: true;
tablespace?: {type: 'origin'; value: string; }
where?: where_clause;
}
export type create_index_stmt = AstStatement<create_index_stmt_node>;
export type column_order_list = column_order[];
export type column_order = {
column: expr;
collate: collate_expr;
opclass: ident;
order: 'asc' | 'desc';
nulls: 'nulls last' | 'nulls first';
};
export type create_like_table_simple = { type: 'like'; table: table_ref_list; };
export type create_like_table = create_like_table_simple | create_like_table_simple & { parentheses?: boolean; };
export type create_table_definition = create_definition[];
export type create_definition = create_column_definition | create_index_definition | create_fulltext_spatial_index_definition | create_constraint_definition;
export type create_column_definition = {
column: column_ref;
definition: data_type;
nullable: column_constraint['nullable'];
default_val: column_constraint['default_val'];
auto_increment?: 'auto_increment';
unique_or_primary?: 'unique' | 'primary key';
comment?: keyword_comment;
collate?: collate_expr;
column_format?: column_format;
storage?: storage;
reference_definition?: reference_definition;
resource: 'column';
};
export type column_constraint = { nullable: literal_null | literal_not_null; default_val: default_expr; };
export type collate_expr = { type: 'collate'; value: ident; };
export type column_format = { type: 'column_format'; value: 'fixed' | 'dynamic' | 'default'; };
export type storage = { type: 'storage'; value: 'disk' | 'memory' };
export type default_expr = { type: 'default'; value: literal | expr; };
export type drop_index_opt = (ALTER_ALGORITHM | ALTER_LOCK)[];
export interface drop_stmt_node {
type: 'drop';
keyword: 'table';
name: table_ref_list;
}
export interface drop_index_stmt_node {
type: 'drop';
keyword: string;
name: column_ref;
table: table_name;
options?: drop_index_opt;
}
export type drop_stmt = AstStatement<drop_stmt_node> | AstStatement<drop_index_stmt_node>;
export interface truncate_stmt_node {
type: 'trucate';
keyword: 'table';
name: table_ref_list;
}
export type truncate_stmt = AstStatement<truncate_stmt_node>;
export interface use_stmt_node {
type: 'use';
db: ident;
}
export type use_stmt = AstStatement<use_stmt_node>;
export interface alter_table_stmt_node {
type: 'alter';
table: table_ref_list;
expr: alter_action_list;
}
export type alter_table_stmt = AstStatement<alter_table_stmt_node>;
export type alter_action_list = alter_action[];
export type alter_action = ALTER_ADD_COLUMN | ALTER_DROP_COLUMN | ALTER_ADD_INDEX_OR_KEY | ALTER_ADD_FULLETXT_SPARITAL_INDEX | ALTER_RENAME_TABLE | ALTER_ALGORITHM | ALTER_LOCK;
export type ALTER_ADD_COLUMN = {
action: 'add';
keyword: KW_COLUMN;
resource: 'column';
type: 'alter';
} & create_column_definition;;
export type ALTER_DROP_COLUMN = {
action: 'drop';
collumn: column_ref;
keyword: KW_COLUMN;
resource: 'column';
type: 'alter';
};
export type ALTER_ADD_INDEX_OR_KEY = {
action: 'add';
type: 'alter';
} & create_index_definition;
export type ALTER_RENAME_TABLE = {
action: 'rename';
type: 'alter';
resource: 'table';
keyword?: 'to' | 'as';
table: ident;
};
export type ALTER_ALGORITHM = {
type: 'alter';
keyword: 'algorithm';
resource: 'algorithm';
symbol?: '=';
algorithm: 'DEFAULT' | 'INSTANT' | 'INPLACE' | 'COPY';
};
export type ALTER_LOCK = {
type: 'alter';
keyword: 'lock';
resource: 'lock';
symbol?: '=';
lock: 'DEFAULT' | 'NONE' | 'SHARED' | 'EXCLUSIVE';
};
export type create_index_definition = {
index: column;
definition: cte_column_definition;
keyword: 'index' | 'key';
index_type?: index_type;
resource: 'index';
index_options?: index_options;
};
export type create_fulltext_spatial_index_definition = {
index: column;
definition: cte_column_definition;
keyword: 'fulltext' | 'spatial' | 'fulltext key' | 'spatial key' | 'fulltext index' | 'spatial index';
index_options?: index_options;
resource: 'index';
};
export type create_constraint_definition = create_constraint_primary | create_constraint_unique | create_constraint_foreign;
export type constraint_name = { keyword: 'constraint'; constraint: ident; };
export type create_constraint_primary = {
constraint?: constraint_name['constraint'];
definition: cte_column_definition;
constraint_type: 'primary key';
index_type?: index_type;
resource: 'constraint';
index_options?: index_options;
};
export type create_constraint_unique = {
constraint?: constraint_name['constraint'];
definition: cte_column_definition;
constraint_type: 'unique key' | 'unique' | 'unique index';
index_type?: index_type;
resource: 'constraint';
index_options?: index_options;
};
export type create_constraint_foreign = {
constraint?: constraint_name['constraint'];
definition: cte_column_definition;
constraint_type: 'FOREIGN KEY';
keyword: constraint_name['keyword'];
index?: column;
resource: 'constraint';
reference_definition?: reference_definition;
};
export type reference_definition = {
definition: cte_column_definition;
table: table_ref_list;
keyword: 'references';
match: 'match full' | 'match partial' | 'match simple';
on_delete?: on_reference;
on_update?: on_reference;
};
export type on_reference = { type: 'on delete' | 'on update'; value: reference_option; };
export type reference_option = 'restrict' | 'cascade' | 'set null' | 'no action' | 'set default';
export type create_constraint_trigger = {
type: 'create';
constraint: string;
location: 'before' | 'after' | 'instead of';
events: trigger_event_list;
table: table_name;
from?: table_name;
deferrable?: trigger_deferrable;
for_each?: trigger_for_row;
when?: trigger_when;
execute: {
keyword: 'execute procedure';
expr: proc_func_call;
};
constraint_type: 'trigger';
keyword: 'trigger';
constraint_kw: 'constraint';
resource: 'constraint';
};
export type trigger_event = { keyword: 'insert' | 'delete' | 'truncate' } | { keyword: 'update'; args?: { keyword: 'of', columns: column_ref_list; }};
export type trigger_event_list = trigger_event[];;
export type trigger_deferrable = { keyword: 'deferrable' | 'not deferrable'; args: 'initially immediate' | 'initially deferred' };
export type trigger_for_row = { keyword: 'for' | 'for each'; args: 'row' | 'statement' };
export type trigger_when = { type: 'when'; cond: expr; parentheses: true; };
export type table_options = table_option[];
export type create_option_character_set_kw = string;
export type create_option_character_set = {
keyword: 'character set' | 'charset' | 'collate' | 'default character set' | 'default charset' | 'default collate';
symbol: '=';
value: ident_name;
};
export type table_option = {
keyword: 'auto_increment' | 'avg_row_length' | 'key_block_size' | 'max_rows' | 'min_rows' | 'stats_sample_pages';
symbol: '=';
value: number; // <== literal_numeric['value']
} | create_option_character_set | { keyword: 'connection' | 'comment'; symbol: '='; value: string; } | { keyword: 'compression'; symbol: '='; value: "'ZLIB'" | "'LZ4'" | "'NONE'" } | { keyword: 'engine'; symbol: '='; value: string; };
export type ALTER_ADD_FULLETXT_SPARITAL_INDEX = create_fulltext_spatial_index_definition & { action: 'add'; type: 'alter' };
export interface rename_stmt_node {
type: 'rename';
table: table_to_list;
}
export type rename_stmt = AstStatement<rename_stmt_node>;
export interface set_stmt_node {
type: 'set';
expr: assign_stmt & { keyword?: 'GLOBAL' | 'SESSION' | 'LOCAL' | 'PERSIST' | 'PERSIST_ONLY'; };
}
export type set_stmt = AstStatement<set_stmt_node>;
export type lock_mode = { mode: string; };
export interface lock_stmt_node {
type: 'lock';
keyword: 'lock';
tables: [[table_base], ...{table: table_ref}[]]; // see table_ref_list
lock_mode?: lock_mode;
nowait?: 'NOWAIT';
}
export type lock_stmt = AstStatement<lock_stmt_node>;
export interface call_stmt_node {
type: 'call';
expr: proc_func_call;
}
export type call_stmt = AstStatement<call_stmt_node>;
export interface select_stmt_node extends select_stmt_nake {
parentheses_symbol: true;
}
export type select_stmt = select_stmt_nake | select_stmt_node;
export type with_clause = cte_definition[] | [cte_definition & {recursive: true; }];
export type cte_definition = { name: ident_name; stmt: union_stmt; columns?: cte_column_definition; };
export type cte_column_definition = column[];
export type select_stmt_nake = {
with?: with_clause;
type: 'select';
options?: option_clause;
distinct?: 'DISTINCT';
columns: column_clause;
from?: from_clause;
where?: where_clause;
groupby?: group_by_clause;
having?: having_clause;
orderby?: order_by_clause;
limit?: limit_clause;
};
export type option_clause = query_option[];
export type query_option = 'SQL_CALC_FOUND_ROWS'| 'SQL_CACHE'| 'SQL_NO_CACHE'| 'SQL_BIG_RESULT'| 'SQL_SMALL_RESULT'| 'SQL_BUFFER_RESULT';
export type column_clause = 'ALL' | '*' | column_list_item[] | column_list_item[];
export type column_list_item = { type: 'cast'; expr: expr; symbol: '::'; target: data_type; as?: null; } | { type: 'star_ref'; expr: column_ref; as: null; } | { type: 'expr'; expr: expr; as?: alias_clause; };
export type alias_clause = alias_ident | ident;
export type from_clause = table_ref_list;
export type table_to_list = table_to_item[];
export type table_to_item = table_name[];
export type index_type = { keyword: 'using'; type: 'btree' | 'hash' | 'gist' | 'gin' };
export type index_options_list = index_option[];
export type index_options = index_option[];
export type index_option = { type: 'key_block_size'; symbol: '='; expr: number; } | { type: ident_name; symbol: '='; expr: number | {type: 'origin'; value: ident; }; } | index_type | { type: 'with parser'; expr: ident_name } | { type: 'visible'; expr: 'visible' } | { type: 'invisible'; expr: 'invisible' } | keyword_comment;
export type table_ref_list = [table_base, ...table_ref[]];
export type table_ref = table_base | table_join;
export type table_join = table_base & {join: join_op; using: ident_name[]; } | table_base & {join: join_op; on?: on_clause; } | {
expr: union_stmt & { parentheses: true; };
as?: alias_clause;
join: join_op;
on?: on_clause;
};
export type table_base = { type: 'dual' } | table_name & { as?: alias_clause; } | { expr: union_stmt; as?: alias_clause; };
export type join_op = 'LEFT JOIN' | 'RIGHT JOIN' | 'FULL JOIN' | 'INNER JOIN';
export type table_name = { db?: ident; table: ident | '*'; };
export type on_clause = expr;
export type where_clause = expr;
export type group_by_clause = expr_list['value'];
export type column_ref_list = column_ref[];
export type having_clause = expr;
export type as_window_specification = { window_specification: window_specification; parentheses: boolean };
export type window_specification = { name: null; partitionby: partition_by_clause; orderby: order_by_clause; window_frame_clause: string };
export type window_specification_frameless = { name: null; partitionby: partition_by_clause; orderby: order_by_clause; window_frame_clause: null };
export type window_frame_clause = string;
export type window_frame_following = string | window_frame_current_row;
export type window_frame_preceding = string | window_frame_current_row;
export type window_frame_current_row = { type: 'single_quote_string'; value: string };
export type window_frame_value = literal_string | literal_numeric;
export type partition_by_clause = column_clause;
export type order_by_clause = order_by_list;
export type order_by_list = order_by_element[];
export type order_by_element = { expr: expr; type: 'ASC' | 'DESC'; };
export type number_or_param = literal_numeric | param;
export type limit_clause = { separator: 'offset' | ''; value: [number_or_param | { type: 'origin', value: 'all' }, number_or_param?] };
export interface update_stmt_node {
type: 'update';
table: table_ref_list;
set: set_list;
where?: where_clause;
returning?: returning_stmt;
}
export type update_stmt = AstStatement<update_stmt_node>;
export interface table_ref_addition extends table_name {
addition: true;
as?: alias_clause;
}
export interface delete_stmt_node {
type: 'delete';
table?: table_ref_list | [table_ref_addition];
where?: where_clause;
}
export type delete_stmt = AstStatement<delete_stmt_node>;
export type set_list = set_item[];
export type set_item = { column: ident; value: additive_expr; table?: ident;} | { column: ident; value: column_ref; table?: ident; keyword: 'values' };
export type returning_stmt = { type: 'returning'; columns: column_ref_list | column_ref; };
export type insert_value_clause = value_clause | select_stmt_nake;
export type insert_partition = ident_name[] | value_item;
export interface replace_insert_stmt_node {
type: 'insert' | 'replace';
table?: [table_name];
columns: column_list;
values: insert_value_clause;
partition?: insert_partition;
returning?: returning_stmt;
}
export type replace_insert_stmt = AstStatement<replace_insert_stmt_node>;
export type insert_no_columns_stmt = AstStatement<replace_insert_stmt_node>;
export type replace_insert = 'insert' | 'replace';
export type value_clause = value_list;
export type value_list = value_item[];
export type value_item = expr_list;
export type expr_list = { type: 'expr_list'; value: expr[] };
export type interval_expr = { type: 'interval', expr: expr; unit: interval_unit; };
export type case_expr = {
type: 'case';
expr?: expr;
// nb: Only the last element is a case_else
args: (case_when_then | case_else)[];
};
export type case_when_then = { type: 'when'; cond: expr; result: expr; };
export type case_else = { type: 'else'; condition?: never; result: expr; };
export type expr = logic_operator_expr | unary_expr | or_expr | select_stmt;
export type BINARY_OPERATORS = LOGIC_OPERATOR | 'OR' | 'AND' | multiplicative_operator | additive_operator
| arithmetic_comparison_operator
| 'IN' | 'NOT IN'
| 'BETWEEN' | 'NOT BETWEEN'
| 'IS' | 'IS NOT'
| 'LIKE'
| '@>' | '<@' | OPERATOR_CONCATENATION | DOUBLE_WELL_ARROW | WELL_ARROW | '?' | '?|' | '?&' | '#-'
export interface binary_expr {
type: 'binary_expr',
operator: BINARY_OPERATORS,
left: expr,
right: expr
}
export type logic_operator_expr = binary_expr;
export type UNARY_OPERATORS = '+' | '-' | 'EXISTS' | 'NOT EXISTS' | 'NULL'
export type unary_expr = {
type: 'unary_expr',
operator: UNARY_OPERATORS,
expr: expr;
parentheses?: boolean;
};
export type or_and_where_expr = binary_expr;
export type parentheses_or_expr = binary_expr;
export type or_expr = binary_expr;
export type and_expr = binary_expr;
export type not_expr = comparison_expr | exists_expr | unary_expr;
export type comparison_expr = binary_expr | literal_string | column_ref;
export type exists_expr = unary_expr;
export type exists_op = 'NOT EXISTS' | KW_EXISTS;
export type comparison_op_right = arithmetic_op_right | in_op_right | between_op_right | is_op_right | like_op_right | jsonb_op_right;
export type arithmetic_op_right = { type: 'arithmetic'; tail: any };
export type arithmetic_comparison_operator = ">=" | ">" | "<=" | "<>" | "<" | "=" | "!=";
export type is_op_right = { op: 'IS'; right: additive_expr; } | { type: 'origin'; value: string; } | { type: 'IS NOT'; right: additive_expr; };
export type between_op_right = { op: 'BETWEEN' | 'NOT BETWEEN'; right: { type: 'expr_list'; value: [expr, expr] } };
export type between_or_not_between_op = 'NOT BETWEEN' | KW_BETWEEN;
export type like_op = 'LIKE' | KW_LIKE | KW_ILIKE;
export type in_op = 'NOT IN' | KW_IN;
export type like_op_right = { op: like_op; right: literal | comparison_expr};
export type in_op_right = {op: in_op; right: expr_list | var_decl | literal_string; };
export type jsonb_op_right = { op: string; right: expr };
export type additive_expr = binary_expr;
export type additive_operator = "+" | "-";
export type multiplicative_expr = binary_expr;
export type multiplicative_operator = "*" | "/" | "%";
export type primary = cast_expr | literal | aggr_func | window_func | func_call | case_expr | interval_expr | column_ref | param | expr | binary_expr | expr_list | var_decl | { type: 'origin'; value: string; };
export type column_ref = {
type: 'column_ref';
table: ident;
column: column | '*';
arrow?: '->>' | '->';
property?: literal_string | literal_numeric;
};
export type column_list = column[];
export type ident = string;
export type alias_ident = string;
export type quoted_ident = double_quoted_ident | single_quoted_ident | backticks_quoted_ident;
export type double_quoted_ident = string;
export type single_quoted_ident = string;
export type backticks_quoted_ident = string;
export type column = string | quoted_ident;
export type column_name = string;
export type ident_name = string;
type ident_start = never;
type ident_part = never;
type column_part = never;
export type param = { type: 'param'; value: ident_name };
export type over_partition = { type: 'windows'; as_window_specification: as_window_specification } | { partitionby: partition_by_clause; orderby: order_by_clause };
export type aggr_func = aggr_fun_count | aggr_fun_smma | aggr_array_agg;
export type window_func = window_fun_rank | window_fun_laglead | window_fun_firstlast;
export type window_fun_rank = { type: 'window_func'; name: string; over: over_partition };
export type window_fun_laglead = { type: 'window_func'; name: string; args: expr_list; consider_nulls: string; over: over_partition };
export type window_fun_firstlast = window_fun_laglead;
type KW_FIRST_LAST_VALUE = never;
type KW_WIN_FNS_RANK = never;
type KW_LAG_LEAD = never;
export type consider_nulls_clause = string;
export type aggr_fun_smma = { type: 'aggr_func'; name: 'SUM' | 'MAX' | 'MIN' | 'AVG'; args: { expr: additive_expr }; over: over_partition };
type KW_SUM_MAX_MIN_AVG = never;
export type aggr_fun_count = { type: 'aggr_func'; name: 'COUNT'; args:count_arg; over: over_partition };
export type distinct_args = { distinct: 'DISTINCT'; expr: column_ref; };
export type count_arg = { expr: star_expr } | distinct_args;
export type aggr_array_agg = { type: 'aggr_func'; args:count_arg; name: 'ARRAY_AGG'; orderby?: order_by_clause };
export type star_expr = { type: 'star'; value: '*' };
export type func_call = { type: 'function'; name: string; args: expr_list; } | { type: 'function'; name: string; args: expr_list; over?: over_partition; } | extract_func;
export type extract_filed = "CENTURY" | "DAY" | "DECADE" | "DOW" | "DOY" | "EPOCH" | "HOUR" | "ISODOW" | "ISOYEAR" | "MICROSECONDS" | "MILLENNIUM" | "MILLISECONDS" | "MINUTE" | "MONTH" | "QUARTER" | "SECOND" | "TIMEZONE" | "TIMEZONE_HOUR" | "TIMEZONE_MINUTE" | "WEEK" | 'string';
export type extract_func = { type: 'extract'; args: { field: extract_filed; cast_type: 'TIMESTAMP' | 'INTERVAL' | 'TIME'; source: expr; }};
export type scalar_func = KW_CURRENT_DATE | KW_CURRENT_TIME | KW_CURRENT_TIMESTAMP | KW_CURRENT_USER | KW_USER | KW_SESSION_USER | KW_SYSTEM_USER;
export type cast_expr = {
as?: alias_clause,
type: 'cast';
expr: expr | literal | aggr_func | func_call | case_expr | interval_expr | column_ref | param
| expr;
symbol: '::' | 'as',
target: data_type;
};
export type signedness = KW_SIGNED | KW_UNSIGNED;
export type literal = literal_string | literal_numeric | literal_bool | literal_null | literal_datetime | literal_array;
export type literal_array = {
expr_list: expr_list | {type: 'origin', value: ident },
type: string,
keyword: string,
brackets: boolean
};
export type literal_list = literal[];
export type literal_null = { type: 'null'; value: null };
export type literal_not_null = { type: 'not null'; value: 'not null' };
export type literal_bool = { type: 'bool', value: true } | { type: 'bool', value: false };
export type literal_string = { type: 'single_quote_string'; value: string; } | { type: 'string'; value: string; };
export type literal_datetime = { type: 'TIME' | 'DATE' | 'TIMESTAMP' | 'DATETIME', value: string } | { type: 'origin'; value: string; };
export type single_quote_char = string;
export type single_char = string;
export type escape_char = string;
export type line_terminator = string;
export type literal_numeric = number | { type: 'bigint'; value: string; };
export type int = string;
export type frac = string;
export type exp = string;
export type digits = string;
export type digit = string;
export type hexDigit = string;
export type e = string;
type KW_NULL = never;
type KW_DEFAULT = never;
type KW_NOT_NULL = never;
type KW_TRUE = never;
type KW_TO = never;
type KW_FALSE = never;
type KW_SHOW = never;
type KW_DROP = never;
type KW_USE = never;
type KW_ALTER = never;
type KW_SELECT = never;
type KW_UPDATE = never;
type KW_CREATE = never;
type KW_TEMPORARY = never;
type KW_TEMP = never;
type KW_IF_NOT_EXISTS = never;
type KW_DELETE = never;
type KW_INSERT = never;
type KW_RECURSIVE = never;
type KW_REPLACE = never;
type KW_RETURNING = never;
type KW_RENAME = never;
type KW_IGNORE = never;
type KW_EXPLAIN = never;
type KW_PARTITION = never;
type KW_INTO = never;
type KW_FROM = never;
type KW_SET = never;
type KW_LOCK = never;
type KW_AS = never;
type KW_TABLE = never;
type KW_DATABASE = never;
type KW_SCHEME = never;
type KW_SEQUENCE = never;
type KW_TABLESPACE = never;
type KW_COLLATE = never;
type KW_ON = never;
type KW_LEFT = never;
type KW_RIGHT = never;
type KW_FULL = never;
type KW_INNER = never;
type KW_JOIN = never;
type KW_OUTER = never;
type KW_UNION = never;
type KW_VALUES = never;
type KW_USING = never;
type KW_WHERE = never;
type KW_WITH = never;
type KW_GROUP = never;
type KW_BY = never;
type KW_ORDER = never;
type KW_HAVING = never;
type KW_LIMIT = never;
type KW_OFFSET = never;
type KW_ASC = never;