UPDATE
UPDATE
changes values stored in user-created tables.
Syntax
Field | Use |
---|---|
UPDATE table_name | The table whose values you want to update. |
alias | Only permit references to table_name as alias. |
SET col_ref = expr | Assign the value of expr to col_ref . |
WHERE condition | Only update rows which evaluate to true for condition. |
Details
UPDATE
cannot currently…
- Be used inside transactions
- Reference other tables
Examples
CREATE TABLE update_me (a int, b text);
INSERT INTO update_me VALUES (1, 'hello'), (2, 'goodbye');
UPDATE update_me SET a = a + 2 WHERE b = 'hello';
SELECT * FROM update_me;
a | b
---+---------
3 | hello
2 | goodbye
UPDATE update_me SET b = 'aloha';
SELECT * FROM update_me;
a | b
---+-------
2 | aloha
3 | aloha