2023-11-09 11:53:40 +08:00
|
|
|
UPDATE MY_TABLE SET A = 5;
|
|
|
|
|
|
|
|
UPDATE weather
|
|
|
|
SET temp_hi = temp_hi - 2, temp_lo = temp_lo - 2
|
|
|
|
WHERE date > '1994-11-28';
|
|
|
|
|
|
|
|
-- Transactions
|
|
|
|
UPDATE accounts SET balance = balance - 100.00
|
|
|
|
WHERE name = 'Alice';
|
|
|
|
UPDATE branches SET balance = balance - 100.00
|
|
|
|
WHERE name = (SELECT branch_name FROM accounts WHERE name = 'Alice');
|
|
|
|
UPDATE accounts SET balance = balance + 100.00
|
|
|
|
WHERE name = 'Bob';
|
|
|
|
UPDATE branches SET balance = balance + 100.00
|
|
|
|
WHERE name = (SELECT branch_name FROM accounts WHERE name = 'Bob');
|
|
|
|
|
|
|
|
UPDATE accounts SET balance = balance - 100.00
|
|
|
|
WHERE name = 'Alice';
|
|
|
|
|
|
|
|
UPDATE mytable SET a = 5, b = b * 3, c = c + 1 WHERE a > 0;
|
|
|
|
|
|
|
|
-- Arrays -- Modifying Arrays
|
|
|
|
UPDATE sal_emp SET pay_by_quarter = ARRAY[25000,25000,27000,27000]
|
|
|
|
WHERE name = 'Carol';
|
|
|
|
|
|
|
|
UPDATE sal_emp SET pay_by_quarter[1:2] = '{27000,27000}'
|
|
|
|
WHERE name = 'Carol';
|
|
|
|
|
|
|
|
--
|
|
|
|
|
|
|
|
-- UPDATE
|
|
|
|
WITH RECURSIVE query_name (id) AS (SELECT id FROM table_expression)
|
|
|
|
UPDATE ONLY table_name * AS alias
|
2023-11-15 15:34:42 +08:00
|
|
|
SET column_name = DEFAULT, (column_name, column_nam2) = ROW ( a+1,DEFAULT)
|
2023-11-09 11:53:40 +08:00
|
|
|
FROM from_list
|
|
|
|
WHERE a=b
|
|
|
|
RETURNING * AS output_name;
|
|
|
|
UPDATE table_name SET column_name = a + 3;
|