UPDATE¶
SQL command to update rows in a table.
Syntax¶
Parameters¶
tableName
The name of the target table
columnName
The name of one of the target column in the target table
literal
A literal whose type must be compatible with the target column
identifier
A database identifier whose type must be compatible with the target column
predicate
A predicate which should evaluate to true for the given row to be updated
Examples¶
Update a column¶
SELECT * FROM T;
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
UPDATE T SET C = 20;
SELECT * FROM T;
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Update a column for rows that match a certain predicate¶
SELECT * FROM T;
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
UPDATE T SET C = NULL WHERE C IS NOT NULL;
SELECT * FROM T;
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Update multiple columns¶
SELECT * FROM T;
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
UPDATE T SET B = 'zero', C = 0.0 WHERE C IS NULL;
SELECT * FROM T;
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Update field inside a STRUCT¶
SELECT * FROM T;
|
|
|
---|---|---|
|
|
|
|
|
|
UPDATE T SET C.S1 = 45 WHERE C.S2 = 200;
SELECT * FROM T;
|
|
|
---|---|---|
|
|
|
|
|
|
Update STRUCT field¶
SELECT * FROM T;
|
|
|
---|---|---|
|
|
|
|
|
|
UPDATE T SET C = (0, 0) WHERE A = 2;
SELECT * FROM T;
|
|
|
---|---|---|
|
|
|
|
|
|