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

1095
grammar.js

File diff suppressed because it is too large Load diff

View file

@ -748,9 +748,14 @@
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_list_of_identifiers"
},
"named": true,
"value": "columns"
},
{
"type": "BLANK"
}
@ -836,6 +841,54 @@
"named": false,
"value": "values"
},
{
"type": "SYMBOL",
"name": "insert_values"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "insert_values"
}
]
}
}
]
},
{
"type": "SYMBOL",
"name": "select_statement"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "select_statement"
},
{
"type": "STRING",
"value": ")"
}
]
}
]
},
"insert_values": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
@ -879,29 +932,6 @@
}
]
},
{
"type": "SYMBOL",
"name": "select_statement"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "select_statement"
},
{
"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

@ -8,11 +8,77 @@ insert into my_table values(1);
(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,10 +104,12 @@ 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);
--------------------------------------------------------------------------------
@ -47,13 +118,16 @@ insert into foo.my_table values(1, 2);
(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));
--------------------------------------------------------------------------------
@ -62,18 +136,22 @@ insert into foo.my_table values(1, DEFAULT, (select 1, 2));
(insert_statement
(identifier)
(insert_items
(insert_item
(number))
(insert_values
(insert_item (number))
(insert_item)
(insert_item
(select_statement
(select_item
(number))
(select_item
(number)))))))
(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,16 +186,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)
)
)
)
)
)
)
)
================================================================================
returning
insert into with returning clause
================================================================================
insert into foo values (1) returning *, 1;
--------------------------------------------------------------------------------
@ -120,16 +210,19 @@ insert into foo values(1) returning *, 1;
(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);
@ -141,19 +234,28 @@ 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
returning id into _var;
@ -162,18 +264,25 @@ returning id into _var;
(source_file
(insert_statement
(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.