VALUES
VALUES
constructs a relation from a list of parenthesized value expressions.
Syntax
VALUES ( expr [, ...] ) [, ( expr [, ...] ) ... ]
Each parenthesis represents a single row. The comma-delimited expressions in the parenthesis represent the values of the columns in that row.
Details
VALUES
expressionscan be used anywhere that SELECT
statements are valid.
They are most commonly used in INSERT
statements, but can also be used
on their own.
Examples
Use VALUES
in an INSERT
VALUES
expressions are most commonly used in INSERT
statements. The
following example uses a VALUES
expression in an INSERT
statement:
INSERT INTO my_table VALUES (1, 2), (3, 4);
Use VALUES
as a standalone expression
VALUES
expression can be used anywhere that SELECT
statements are valid.
For example:
-
As a standalone expression:
VALUES (1, 2, 3), (4, 5, 6);
The above expression returns the following results:
column1 | column2 | column3 --------+---------+--------- 1 | 2 | 3 4 | 5 | 6
-
With an
ORDER BY
andLIMIT
:VALUES (1), (2), (3) ORDER BY column1 DESC LIMIT 2;
The above expression returns the following results:
column1 -------- 3 2