update
This commit is contained in:
parent
48e0701909
commit
208d770137
3 changed files with 184 additions and 5 deletions
|
@ -103,7 +103,7 @@ insert into foo values(1) returning *, 1;
|
||||||
(insert_items
|
(insert_items
|
||||||
(insert_item
|
(insert_item
|
||||||
(number)))
|
(number)))
|
||||||
(insert_returning
|
(returning
|
||||||
(select_item
|
(select_item
|
||||||
(star))
|
(star))
|
||||||
(select_item
|
(select_item
|
||||||
|
@ -153,7 +153,7 @@ returning id into _var;
|
||||||
(from_item
|
(from_item
|
||||||
(from_table
|
(from_table
|
||||||
(identifier))))))
|
(identifier))))))
|
||||||
(insert_returning
|
(returning
|
||||||
(select_item
|
(select_item
|
||||||
(identifier)))
|
(identifier)))
|
||||||
(into
|
(into
|
||||||
|
|
168
corpus/update_statement.txt
Normal file
168
corpus/update_statement.txt
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
================================================================================
|
||||||
|
update one field
|
||||||
|
================================================================================
|
||||||
|
update items set foo = 'bar';
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(source_file
|
||||||
|
(update_statement
|
||||||
|
(identifier)
|
||||||
|
(update_set
|
||||||
|
(identifier)
|
||||||
|
(update_value
|
||||||
|
(string)))))
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
alias
|
||||||
|
================================================================================
|
||||||
|
update items as t set foo = 'bar';
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(source_file
|
||||||
|
(update_statement
|
||||||
|
(identifier)
|
||||||
|
(identifier)
|
||||||
|
(update_set
|
||||||
|
(identifier)
|
||||||
|
(update_value
|
||||||
|
(string)))))
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
update many fields
|
||||||
|
================================================================================
|
||||||
|
update t set col1 = val1, col2 = default returning foo, *;
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(source_file
|
||||||
|
(update_statement
|
||||||
|
(identifier)
|
||||||
|
(update_set
|
||||||
|
(identifier)
|
||||||
|
(update_value
|
||||||
|
(identifier)))
|
||||||
|
(update_set
|
||||||
|
(identifier)
|
||||||
|
(update_value))
|
||||||
|
(returning
|
||||||
|
(select_item
|
||||||
|
(identifier))
|
||||||
|
(select_item
|
||||||
|
(star)))))
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
update many fields(1)
|
||||||
|
================================================================================
|
||||||
|
update t set (col1, col2) = (val1, val2);
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(source_file
|
||||||
|
(update_statement
|
||||||
|
(identifier)
|
||||||
|
(update_set
|
||||||
|
(identifier)
|
||||||
|
(identifier)
|
||||||
|
(update_value
|
||||||
|
(identifier))
|
||||||
|
(update_value
|
||||||
|
(identifier)))))
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
update where
|
||||||
|
================================================================================
|
||||||
|
update t set foo = bar where column1 = 'magic';
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(source_file
|
||||||
|
(update_statement
|
||||||
|
(identifier)
|
||||||
|
(update_set
|
||||||
|
(identifier)
|
||||||
|
(update_value
|
||||||
|
(identifier)))
|
||||||
|
(where_filter
|
||||||
|
(op_expression
|
||||||
|
(identifier)
|
||||||
|
(comparison_op)
|
||||||
|
(string)))))
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
update where subselect
|
||||||
|
================================================================================
|
||||||
|
UPDATE t SET a = b + 1 WHERE id = (SELECT foo FROM bar WHERE c = 'd');
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(source_file
|
||||||
|
(update_statement
|
||||||
|
(identifier)
|
||||||
|
(update_set
|
||||||
|
(identifier)
|
||||||
|
(update_value
|
||||||
|
(op_expression
|
||||||
|
(identifier)
|
||||||
|
(number))))
|
||||||
|
(where_filter
|
||||||
|
(op_expression
|
||||||
|
(identifier)
|
||||||
|
(comparison_op)
|
||||||
|
(select_statement
|
||||||
|
(select_item
|
||||||
|
(identifier))
|
||||||
|
(select_from
|
||||||
|
(from_item
|
||||||
|
(from_table
|
||||||
|
(identifier))))
|
||||||
|
(select_where
|
||||||
|
(where_filter
|
||||||
|
(op_expression
|
||||||
|
(identifier)
|
||||||
|
(comparison_op)
|
||||||
|
(string)))))))))
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
update from
|
||||||
|
================================================================================
|
||||||
|
UPDATE foo SET bar = bar + 1 FROM t WHERE b = 'z';
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(source_file
|
||||||
|
(update_statement
|
||||||
|
(identifier)
|
||||||
|
(update_set
|
||||||
|
(identifier)
|
||||||
|
(update_value
|
||||||
|
(op_expression
|
||||||
|
(identifier)
|
||||||
|
(number))))
|
||||||
|
(from_item
|
||||||
|
(from_table
|
||||||
|
(identifier)))
|
||||||
|
(where_filter
|
||||||
|
(op_expression
|
||||||
|
(identifier)
|
||||||
|
(comparison_op)
|
||||||
|
(string)))))
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
with cte
|
||||||
|
================================================================================
|
||||||
|
with foo as (select * from bar)
|
||||||
|
update foo set bar = 1;
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(source_file
|
||||||
|
(update_statement
|
||||||
|
(with_query
|
||||||
|
(with_query_item
|
||||||
|
(identifier)
|
||||||
|
(select_statement
|
||||||
|
(select_item
|
||||||
|
(star))
|
||||||
|
(select_from
|
||||||
|
(from_item
|
||||||
|
(from_table
|
||||||
|
(identifier)))))))
|
||||||
|
(identifier)
|
||||||
|
(update_set
|
||||||
|
(identifier)
|
||||||
|
(update_value
|
||||||
|
(number)))))
|
17
grammar.js
17
grammar.js
|
@ -52,6 +52,7 @@ module.exports = grammar({
|
||||||
$.select_statement,
|
$.select_statement,
|
||||||
$.insert_statement,
|
$.insert_statement,
|
||||||
$.delete_statement,
|
$.delete_statement,
|
||||||
|
$.update_statement,
|
||||||
$.grant_statement,
|
$.grant_statement,
|
||||||
$.create_trigger_statement,
|
$.create_trigger_statement,
|
||||||
$.create_sequence_statement,
|
$.create_sequence_statement,
|
||||||
|
@ -60,6 +61,15 @@ module.exports = grammar({
|
||||||
$.do_block,
|
$.do_block,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
update_statement: $ => seq(
|
||||||
|
optional($.with_query),
|
||||||
|
kw("update"), $.identifier, optional(seq(optional(kw("as")), $.identifier)),
|
||||||
|
kw("set"), commaSep1($.update_set),
|
||||||
|
optional(seq(kw("from"), commaSep1($.from_item))),
|
||||||
|
optional($.where_filter),
|
||||||
|
optional($.returning),
|
||||||
|
),
|
||||||
|
|
||||||
drop_function_statement: $ => seq(
|
drop_function_statement: $ => seq(
|
||||||
kw("drop"), kw("function"),
|
kw("drop"), kw("function"),
|
||||||
commaSep1($.drop_function_item),
|
commaSep1($.drop_function_item),
|
||||||
|
@ -85,11 +95,12 @@ module.exports = grammar({
|
||||||
))
|
))
|
||||||
),
|
),
|
||||||
|
|
||||||
// TODO(chrde): update, values
|
// TODO(chrde): values
|
||||||
_with_query_statement: $ => choice(
|
_with_query_statement: $ => choice(
|
||||||
$.select_statement,
|
$.select_statement,
|
||||||
$.insert_statement,
|
$.insert_statement,
|
||||||
$.delete_statement,
|
$.delete_statement,
|
||||||
|
$.update_statement,
|
||||||
),
|
),
|
||||||
|
|
||||||
insert_statement: $ => seq(
|
insert_statement: $ => seq(
|
||||||
|
@ -97,7 +108,7 @@ module.exports = grammar({
|
||||||
kw("insert"), kw("into"), $.identifier, optional($.as),
|
kw("insert"), kw("into"), $.identifier, optional($.as),
|
||||||
optional($._list_of_identifiers),
|
optional($._list_of_identifiers),
|
||||||
$.insert_items, optional($.insert_conflict),
|
$.insert_items, optional($.insert_conflict),
|
||||||
optional($.insert_returning),
|
optional($.returning),
|
||||||
optional($.into),
|
optional($.into),
|
||||||
),
|
),
|
||||||
insert_items: $ => choice(
|
insert_items: $ => choice(
|
||||||
|
@ -125,7 +136,7 @@ module.exports = grammar({
|
||||||
seq($._list_of_identifiers, "=", optional(kw("row")), "(", commaSep1($.update_value), ")"),
|
seq($._list_of_identifiers, "=", optional(kw("row")), "(", commaSep1($.update_value), ")"),
|
||||||
),
|
),
|
||||||
update_value: $ => choice(kw("default"), $._value_expression),
|
update_value: $ => choice(kw("default"), $._value_expression),
|
||||||
insert_returning: $ => seq(kw("returning"), commaSep1($.select_item)),
|
returning: $ => seq(kw("returning"), commaSep1($.select_item)),
|
||||||
|
|
||||||
create_table_statement: $ => seq(
|
create_table_statement: $ => seq(
|
||||||
kw("create"), optional($.temporary), optional(kw("unlogged")), kw("table"),
|
kw("create"), optional($.temporary), optional(kw("unlogged")), kw("table"),
|
||||||
|
|
Loading…
Reference in a new issue