
When it's used in other contexts, it might be necessary to specify the correct data type. When VALUES is used in INSERT, the values are all automatically coerced to the data type of the corresponding destination column. in PostgreSQL, but these names might be different in other database systems.) (The default column names for VALUES are column1, column2, etc. It is not required that the AS clause specify names for all the columns, but it's good practice to do so. Note that an AS clause is required when VALUES is used in a FROM clause, just as is true for SELECT. WHERE pno = v.depno AND employees.sales >= v.target
#Postgresql like multiple values update#
UPDATE employees SET salary = salary * v.increaseįROM (VALUES(1, 200000, 1.2), (2, 400000, 1.4)) AS v (depno, target, increase) WHERE f.studio = t.studio AND f.kind = t.kind

VALUES can also be used where a sub- SELECT might be written, for example in a FROM clause:įROM films f, (VALUES('MGM', 'Horror'), ('UA', 'Sci-Fi')) AS t (studio, kind)

In the context of INSERT, entries of a VALUES list can be DEFAULT to indicate that the column default should be used here instead of specifying a value: INSERT INTO films (code, title, did, date_prod, kind) More usually, VALUES is used within a larger SQL command. This will return a table of two columns and three rows.
