ruk·si

🐘 PostgreSQL
UPDATE

Updated at 2015-05-02 14:09

All statements works in PostgreSQL 9.1+. For more PostgreSQL notes, check out PostgreSQL Guide

Updating multiple rows.

UPDATE weather SET
    temp_lo = temp_lo+1,
    temp_hi = temp_lo+15,
    prcp = DEFAULT
WHERE city = 'San Francisco'
AND date = '2003-07-03';
UPDATE employee SET
    sales_count = sales_count + 1
WHERE id = (
    SELECT sales_person
    FROM account
    WHERE name = 'Acme Corporation'
);

Make the statement return a value.

UPDATE weather SET
    temp_lo = temp_lo+1,
    temp_hi = temp_lo+15,
    prcp = DEFAULT
WHERE city = 'San Francisco'
AND date = '2003-07-03'
RETURNING temp_lo, temp_hi, prcp;

Sources