Commit 8d8c236 1 parent b0e6359 commit 8d8c236 Copy full SHA for 8d8c236
File tree 7 files changed +198
-10
lines changed
7 files changed +198
-10
lines changed Original file line number Diff line number Diff line change @@ -2195,12 +2195,18 @@ module.exports = grammar({
2195
2195
$ . identifier ,
2196
2196
) ,
2197
2197
2198
- object_reference : $ => seq (
2199
- optional (
2200
- seq (
2201
- field ( 'schema' , $ . identifier ) ,
2202
- '.' ,
2203
- ) ,
2198
+ object_reference : $ => choice (
2199
+ seq (
2200
+ field ( 'database' , $ . identifier ) ,
2201
+ '.' ,
2202
+ field ( 'schema' , $ . identifier ) ,
2203
+ '.' ,
2204
+ field ( 'name' , $ . identifier ) ,
2205
+ ) ,
2206
+ seq (
2207
+ field ( 'schema' , $ . identifier ) ,
2208
+ '.' ,
2209
+ field ( 'name' , $ . identifier ) ,
2204
2210
) ,
2205
2211
field ( 'name' , $ . identifier ) ,
2206
2212
) ,
Original file line number Diff line number Diff line change @@ -25,6 +25,35 @@ ALTER TABLE my_table
25
25
(keyword_not)
26
26
(keyword_null))))))
27
27
28
+ ================================================================================
29
+ Alter table and add column with FQN
30
+ ================================================================================
31
+
32
+ ALTER TABLE my_database.my_table.my_table
33
+ ADD COLUMN val3 VARCHAR(100) NOT NULL;
34
+
35
+ --------------------------------------------------------------------------------
36
+
37
+ (program
38
+ (statement
39
+ (alter_table
40
+ (keyword_alter)
41
+ (keyword_table)
42
+ (object_reference
43
+ database: (identifier)
44
+ schema: (identifier)
45
+ name: (identifier))
46
+ (add_column
47
+ (keyword_add)
48
+ (keyword_column)
49
+ (column_definition
50
+ name: (identifier)
51
+ type: (varchar
52
+ (keyword_varchar)
53
+ size: (literal))
54
+ (keyword_not)
55
+ (keyword_null))))))
56
+
28
57
================================================================================
29
58
Alter table and add column, eliding column keyword
30
59
================================================================================
Original file line number Diff line number Diff line change @@ -18,6 +18,27 @@ COMMENT ON TABLE my_schema.my_table IS "this table is a test";
18
18
(keyword_is)
19
19
(literal))))
20
20
21
+ ================================================================================
22
+ Comment on table with FQN
23
+ ================================================================================
24
+
25
+ COMMENT ON TABLE my_database.my_schema.my_table IS "this table is a test";
26
+
27
+ --------------------------------------------------------------------------------
28
+
29
+ (program
30
+ (statement
31
+ (comment_statement
32
+ (keyword_comment)
33
+ (keyword_on)
34
+ (keyword_table)
35
+ (object_reference
36
+ database: (identifier)
37
+ schema: (identifier)
38
+ name: (identifier))
39
+ (keyword_is)
40
+ (literal))))
41
+
21
42
================================================================================
22
43
Comment on column is null
23
44
================================================================================
@@ -40,6 +61,29 @@ COMMENT ON COLUMN my_schema.my_table.my_column IS NULL;
40
61
(keyword_is)
41
62
(keyword_null))))
42
63
64
+ ================================================================================
65
+ Comment on column is null with FQN
66
+ ================================================================================
67
+
68
+ COMMENT ON COLUMN my_database.my_schema.my_table.my_column IS NULL;
69
+
70
+ --------------------------------------------------------------------------------
71
+
72
+ (program
73
+ (statement
74
+ (comment_statement
75
+ (keyword_comment)
76
+ (keyword_on)
77
+ (keyword_column)
78
+ (object_reference
79
+ (object_reference
80
+ (identifier)
81
+ (identifier)
82
+ (identifier))
83
+ (identifier))
84
+ (keyword_is)
85
+ (keyword_null))))
86
+
43
87
================================================================================
44
88
Comment on cast
45
89
================================================================================
Original file line number Diff line number Diff line change @@ -24,6 +24,33 @@ CREATE TABLE my_schema.my_table (id BIGINT NOT NULL PRIMARY KEY);
24
24
(keyword_primary)
25
25
(keyword_key))))))
26
26
27
+ ================================================================================
28
+ Create table with FQN
29
+ ================================================================================
30
+
31
+ CREATE TABLE my_database.my_schema.my_table (id BIGINT NOT NULL PRIMARY KEY);
32
+
33
+ --------------------------------------------------------------------------------
34
+
35
+ (program
36
+ (statement
37
+ (create_table
38
+ (keyword_create)
39
+ (keyword_table)
40
+ (object_reference
41
+ database: (identifier)
42
+ schema: (identifier)
43
+ name: (identifier))
44
+ (column_definitions
45
+ (column_definition
46
+ name: (identifier)
47
+ type: (bigint
48
+ (keyword_bigint))
49
+ (keyword_not)
50
+ (keyword_null)
51
+ (keyword_primary)
52
+ (keyword_key))))))
53
+
27
54
================================================================================
28
55
Create table multiple columns
29
56
================================================================================
Original file line number Diff line number Diff line change @@ -15,6 +15,25 @@ DELETE FROM my_table;
15
15
(object_reference
16
16
name: (identifier)))))
17
17
18
+ ================================================================================
19
+ Delete whole table with FQN
20
+ ================================================================================
21
+
22
+ DELETE FROM my_database.my_schema.my_table;
23
+
24
+ --------------------------------------------------------------------------------
25
+
26
+ (program
27
+ (statement
28
+ (delete
29
+ (keyword_delete))
30
+ (from
31
+ (keyword_from)
32
+ (object_reference
33
+ database: (identifier)
34
+ schema: (identifier)
35
+ name: (identifier)))))
36
+
18
37
================================================================================
19
38
Delete whole table and only the whole table
20
39
================================================================================
Original file line number Diff line number Diff line change @@ -14,6 +14,24 @@ DROP TABLE my_table;
14
14
(object_reference
15
15
name: (identifier)))))
16
16
17
+ ================================================================================
18
+ Drop table with FQN
19
+ ================================================================================
20
+
21
+ DROP TABLE my_table.my_schema.my_table;
22
+
23
+ --------------------------------------------------------------------------------
24
+
25
+ (program
26
+ (statement
27
+ (drop_table
28
+ (keyword_drop)
29
+ (keyword_table)
30
+ (object_reference
31
+ database: (identifier)
32
+ schema: (identifier)
33
+ name: (identifier)))))
34
+
17
35
================================================================================
18
36
Drop table and cascade through
19
37
================================================================================
@@ -47,6 +65,24 @@ DROP VIEW my_view;
47
65
(object_reference
48
66
name: (identifier)))))
49
67
68
+ ================================================================================
69
+ Drop view with FQN
70
+ ================================================================================
71
+
72
+ DROP VIEW my_database.my_schema.my_view;
73
+
74
+ --------------------------------------------------------------------------------
75
+
76
+ (program
77
+ (statement
78
+ (drop_view
79
+ (keyword_drop)
80
+ (keyword_view)
81
+ (object_reference
82
+ database: (identifier)
83
+ schema: (identifier)
84
+ name: (identifier)))))
85
+
50
86
================================================================================
51
87
Drop index
52
88
================================================================================
Original file line number Diff line number Diff line change @@ -749,14 +749,37 @@ SELECT * FROM my_schema.my_table;
749
749
schema: (identifier)
750
750
name: (identifier))))))
751
751
752
+ ================================================================================
753
+ Simple select with FQN
754
+ ================================================================================
755
+
756
+ SELECT * FROM my_database.my_schema.my_table;
757
+
758
+ --------------------------------------------------------------------------------
759
+
760
+ (program
761
+ (statement
762
+ (select
763
+ (keyword_select)
764
+ (select_expression
765
+ (term
766
+ value: (all_fields))))
767
+ (from
768
+ (keyword_from)
769
+ (relation
770
+ (object_reference
771
+ database: (identifier)
772
+ schema: (identifier)
773
+ name: (identifier))))))
774
+
752
775
================================================================================
753
776
Simple select with schema and fully-qualified *
754
777
================================================================================
755
778
756
779
SELECT
757
- my_schema.my_table.*
780
+ my_database. my_schema.my_table.*
758
781
FROM
759
- my_schema.my_table;
782
+ my_database. my_schema.my_table;
760
783
761
784
--------------------------------------------------------------------------------
762
785
@@ -768,12 +791,14 @@ FROM
768
791
(term
769
792
value: (all_fields
770
793
(object_reference
794
+ database: (identifier)
771
795
schema: (identifier)
772
796
name: (identifier))))))
773
797
(from
774
798
(keyword_from)
775
799
(relation
776
800
(object_reference
801
+ database: (identifier)
777
802
schema: (identifier)
778
803
name: (identifier))))))
779
804
@@ -782,9 +807,9 @@ Simple select with schema and fully-pathed fields
782
807
================================================================================
783
808
784
809
SELECT
785
- my_schema.my_table.my_field
810
+ my_database. my_schema.my_table.my_field
786
811
FROM
787
- my_schema.my_table;
812
+ my_database. my_schema.my_table;
788
813
789
814
--------------------------------------------------------------------------------
790
815
@@ -796,13 +821,15 @@ FROM
796
821
(term
797
822
value: (field
798
823
(object_reference
824
+ database: (identifier)
799
825
schema: (identifier)
800
826
name: (identifier))
801
827
name: (identifier)))))
802
828
(from
803
829
(keyword_from)
804
830
(relation
805
831
(object_reference
832
+ database: (identifier)
806
833
schema: (identifier)
807
834
name: (identifier))))))
808
835
You can’t perform that action at this time.
0 commit comments