168 lines
4.6 KiB
Text
168 lines
4.6 KiB
Text
================================================================================
|
|
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)))))
|