grammar: add many values to insert into

This commit is contained in:
Dmitriy Pleshevskiy 2023-01-05 23:30:26 +03:00
parent e577e230b1
commit 2479108e10
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
7 changed files with 57451 additions and 56755 deletions

1695
grammar.js

File diff suppressed because it is too large Load diff

View file

@ -748,8 +748,13 @@
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "ALIAS",
"name": "_list_of_identifiers" "content": {
"type": "SYMBOL",
"name": "_list_of_identifiers"
},
"named": true,
"value": "columns"
}, },
{ {
"type": "BLANK" "type": "BLANK"
@ -837,45 +842,24 @@
"value": "values" "value": "values"
}, },
{ {
"type": "STRING", "type": "SYMBOL",
"value": "(" "name": "insert_values"
}, },
{ {
"type": "CHOICE", "type": "REPEAT",
"members": [ "content": {
{ "type": "SEQ",
"type": "SEQ", "members": [
"members": [ {
{ "type": "STRING",
"type": "SYMBOL", "value": ","
"name": "insert_item" },
}, {
{ "type": "SYMBOL",
"type": "REPEAT", "name": "insert_values"
"content": { }
"type": "SEQ", ]
"members": [ }
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "insert_item"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
} }
] ]
}, },
@ -902,6 +886,52 @@
} }
] ]
}, },
"insert_values": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "insert_item"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "insert_item"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
"insert_item": { "insert_item": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [

View file

@ -665,6 +665,21 @@
] ]
} }
}, },
{
"type": "columns",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
{ {
"type": "comparison_kw", "type": "comparison_kw",
"named": true, "named": true,
@ -2294,7 +2309,7 @@
"required": false, "required": false,
"types": [ "types": [
{ {
"type": "insert_item", "type": "insert_values",
"named": true "named": true
}, },
{ {
@ -2316,6 +2331,10 @@
"type": "as", "type": "as",
"named": true "named": true
}, },
{
"type": "columns",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -2343,6 +2362,21 @@
] ]
} }
}, },
{
"type": "insert_values",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "insert_item",
"named": true
}
]
}
},
{ {
"type": "into", "type": "into",
"named": true, "named": true,

112120
src/parser.c

File diff suppressed because it is too large Load diff

View file

@ -1,18 +1,84 @@
================================================================================ ================================================================================
basic basic
================================================================================ ================================================================================
insert into my_table values(1); insert into my_table values (1);
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(insert_statement (insert_statement
(identifier) (identifier)
(insert_items (insert_items
(insert_item (insert_values
(number))))) (insert_item (number))
)
)
)
)
================================================================================ ================================================================================
alias insert into table by specified columns
================================================================================
insert into my_table (name, email, display_name) values
('foo', 'bar@biz.baz', 'Foo bar');
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(columns
(identifier)
(identifier)
(identifier)
)
(insert_items
(insert_values
(insert_item (string))
(insert_item (string))
(insert_item (string))
)
)
)
)
================================================================================
insert into table by specified columns with many values
================================================================================
insert into my_table (name, email, display_name) values
('foo', 'bar@biz.baz', 'Foo bar'),
('foo', 'bar@biz.baz', 'Foo bar'),
('foo', 'bar@biz.baz', 'Foo bar');
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(columns
(identifier)
(identifier)
(identifier)
)
(insert_items
(insert_values
(insert_item (string))
(insert_item (string))
(insert_item (string))
)
(insert_values
(insert_item (string))
(insert_item (string))
(insert_item (string))
)
(insert_values
(insert_item (string))
(insert_item (string))
(insert_item (string))
)
)
)
)
================================================================================
insert into table with alias
================================================================================ ================================================================================
insert into foo.my_table as alias values(1); insert into foo.my_table as alias values(1);
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -20,14 +86,17 @@ insert into foo.my_table as alias values(1);
(source_file (source_file
(insert_statement (insert_statement
(identifier) (identifier)
(as (as (identifier))
(identifier))
(insert_items (insert_items
(insert_item (insert_values
(number))))) (insert_item (number))
)
)
)
)
================================================================================ ================================================================================
default values insert into default values
================================================================================ ================================================================================
insert into foo.my_table default values; insert into foo.my_table default values;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -35,45 +104,54 @@ insert into foo.my_table default values;
(source_file (source_file
(insert_statement (insert_statement
(identifier) (identifier)
(insert_items))) (insert_items)
)
)
================================================================================ ================================================================================
many values insert into with many value items
================================================================================ ================================================================================
insert into foo.my_table values(1, 2); insert into foo.my_table values (1, 2);
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(insert_statement (insert_statement
(identifier) (identifier)
(insert_items (insert_items
(insert_item (insert_values
(number)) (insert_item (number))
(insert_item (insert_item (number))
(number))))) )
)
)
)
================================================================================ ================================================================================
different kind of values insert into with different kind of value items
================================================================================ ================================================================================
insert into foo.my_table values(1, DEFAULT, (select 1, 2)); insert into foo.my_table values (1, DEFAULT, (select 1, 2));
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(insert_statement (insert_statement
(identifier) (identifier)
(insert_items (insert_items
(insert_item (insert_values
(number)) (insert_item (number))
(insert_item) (insert_item)
(insert_item (insert_item
(select_statement (select_statement
(select_item (select_item (number))
(number)) (select_item (number))
(select_item )
(number))))))) )
)
)
)
)
================================================================================ ================================================================================
insert from select insert into from select
================================================================================ ================================================================================
insert into foo.my_table select column1 from foo bar; insert into foo.my_table select column1 from foo bar;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -83,16 +161,22 @@ insert into foo.my_table select column1 from foo bar;
(identifier) (identifier)
(insert_items (insert_items
(select_statement (select_statement
(select_item (select_item (identifier))
(identifier))
(select_from (select_from
(from_item (from_item
(from_table (from_table
(identifier) (identifier)
(identifier)))))))) (identifier)
)
)
)
)
)
)
)
================================================================================ ================================================================================
insert from select(1) insert into a table with the select enclosed in parentheses
================================================================================ ================================================================================
insert into foo.my_table (select column1 from foo bar); insert into foo.my_table (select column1 from foo bar);
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -102,37 +186,46 @@ insert into foo.my_table (select column1 from foo bar);
(identifier) (identifier)
(insert_items (insert_items
(select_statement (select_statement
(select_item (select_item (identifier))
(identifier))
(select_from (select_from
(from_item (from_item
(from_table (from_table
(identifier) (identifier)
(identifier)))))))) (identifier)
)
)
)
)
)
)
)
================================================================================ ================================================================================
returning insert into with returning clause
================================================================================ ================================================================================
insert into foo values(1) returning *, 1; insert into foo values (1) returning *, 1;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(insert_statement (insert_statement
(identifier) (identifier)
(insert_items (insert_items
(insert_item (insert_values
(number))) (insert_item (number))
)
)
(returning (returning
(select_item (select_item (star))
(star)) (select_item (number))
(select_item )
(number))))) )
)
================================================================================ ================================================================================
with cte insert into using with clause
================================================================================ ================================================================================
with foo as (select * from bar) with foo as (select * from bar)
insert into my_table values(1); insert into my_table values (1);
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
@ -141,39 +234,55 @@ insert into my_table values(1);
(with_query_item (with_query_item
(identifier) (identifier)
(select_statement (select_statement
(select_item (select_item (star))
(star))
(select_from (select_from
(from_item (from_item
(from_table (from_table
(identifier))))))) (identifier)
)
)
)
)
)
)
(identifier) (identifier)
(insert_items (insert_items
(insert_item (insert_values
(number))))) (insert_item (number))
)
)
)
)
================================================================================ ================================================================================
returning into insert into statement with returning into clause
================================================================================ ================================================================================
insert into foo(bar, baz) select * from another insert into foo (bar, baz) select * from another
returning id into _var; returning id into _var;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
(source_file (source_file
(insert_statement (insert_statement
(identifier) (identifier)
(identifier) (columns
(identifier) (identifier)
(identifier)
)
(insert_items (insert_items
(select_statement (select_statement
(select_item (select_item (star))
(star))
(select_from (select_from
(from_item (from_item
(from_table (from_table
(identifier)))))) (identifier)
)
)
)
)
)
(returning (returning
(select_item (select_item (identifier))
(identifier))) )
(into (into (identifier))
(identifier)))) )
)

View file

@ -119,7 +119,7 @@ with new as (delete from productes returning *) select 1;
(number)))) (number))))
================================================================================ ================================================================================
with insert select statement using with clause with insert into
================================================================================ ================================================================================
with new as (insert into foo values(1)) select 1; with new as (insert into foo values(1)) select 1;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -132,10 +132,16 @@ with new as (insert into foo values(1)) select 1;
(insert_statement (insert_statement
(identifier) (identifier)
(insert_items (insert_items
(insert_item (insert_values
(number)))))) (insert_item (number))
(select_item )
(number)))) )
)
)
)
(select_item (number))
)
)
================================================================================ ================================================================================
with update with update

Binary file not shown.