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",
"members": [
{
"type": "SYMBOL",
"name": "_list_of_identifiers"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_list_of_identifiers"
},
"named": true,
"value": "columns"
},
{
"type": "BLANK"
@ -837,45 +842,24 @@
"value": "values"
},
{
"type": "STRING",
"value": "("
"type": "SYMBOL",
"name": "insert_values"
},
{
"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": ")"
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "insert_values"
}
]
}
}
]
},
@ -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": {
"type": "CHOICE",
"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",
"named": true,
@ -2294,7 +2309,7 @@
"required": false,
"types": [
{
"type": "insert_item",
"type": "insert_values",
"named": true
},
{
@ -2316,6 +2331,10 @@
"type": "as",
"named": true
},
{
"type": "columns",
"named": true
},
{
"type": "identifier",
"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",
"named": true,

112120
src/parser.c

File diff suppressed because it is too large Load diff

View file

@ -1,18 +1,84 @@
================================================================================
basic
================================================================================
insert into my_table values(1);
insert into my_table values (1);
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(insert_items
(insert_item
(number)))))
(insert_values
(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);
--------------------------------------------------------------------------------
@ -20,14 +86,17 @@ insert into foo.my_table as alias values(1);
(source_file
(insert_statement
(identifier)
(as
(identifier))
(as (identifier))
(insert_items
(insert_item
(number)))))
(insert_values
(insert_item (number))
)
)
)
)
================================================================================
default values
insert into default values
================================================================================
insert into foo.my_table default values;
--------------------------------------------------------------------------------
@ -35,45 +104,54 @@ insert into foo.my_table default values;
(source_file
(insert_statement
(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
(insert_statement
(identifier)
(insert_items
(insert_item
(number))
(insert_item
(number)))))
(insert_values
(insert_item (number))
(insert_item (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
(insert_statement
(identifier)
(insert_items
(insert_item
(number))
(insert_item)
(insert_item
(select_statement
(select_item
(number))
(select_item
(number)))))))
(insert_values
(insert_item (number))
(insert_item)
(insert_item
(select_statement
(select_item (number))
(select_item (number))
)
)
)
)
)
)
================================================================================
insert from select
insert into from select
================================================================================
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)
(insert_items
(select_statement
(select_item
(identifier))
(select_item (identifier))
(select_from
(from_item
(from_table
(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);
--------------------------------------------------------------------------------
@ -102,37 +186,46 @@ insert into foo.my_table (select column1 from foo bar);
(identifier)
(insert_items
(select_statement
(select_item
(identifier))
(select_item (identifier))
(select_from
(from_item
(from_table
(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
(insert_statement
(identifier)
(insert_items
(insert_item
(number)))
(insert_values
(insert_item (number))
)
)
(returning
(select_item
(star))
(select_item
(number)))))
(select_item (star))
(select_item (number))
)
)
)
================================================================================
with cte
insert into using with clause
================================================================================
with foo as (select * from bar)
insert into my_table values(1);
insert into my_table values (1);
--------------------------------------------------------------------------------
(source_file
@ -141,39 +234,55 @@ insert into my_table values(1);
(with_query_item
(identifier)
(select_statement
(select_item
(star))
(select_item (star))
(select_from
(from_item
(from_table
(identifier)))))))
(identifier)
)
)
)
)
)
)
(identifier)
(insert_items
(insert_item
(number)))))
(insert_values
(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;
--------------------------------------------------------------------------------
(source_file
(insert_statement
(identifier)
(identifier)
(identifier)
(columns
(identifier)
(identifier)
)
(insert_items
(select_statement
(select_item
(star))
(select_item (star))
(select_from
(from_item
(from_table
(identifier))))))
(identifier)
)
)
)
)
)
(returning
(select_item
(identifier)))
(into
(identifier))))
(select_item (identifier))
)
(into (identifier))
)
)

View file

@ -119,7 +119,7 @@ with new as (delete from productes returning *) select 1;
(number))))
================================================================================
with insert
select statement using with clause with insert into
================================================================================
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
(identifier)
(insert_items
(insert_item
(number))))))
(select_item
(number))))
(insert_values
(insert_item (number))
)
)
)
)
)
(select_item (number))
)
)
================================================================================
with update

Binary file not shown.