VALUES lists
A VALUES list is a table of literal rows that you write in the query. Put each row in parentheses, and separate the rows with commas. Every row must have the same number of values.
Use a VALUES list in the FROM clause, in parentheses, with an alias that names its columns. Without column names, the columns are named col0, col1, and so on.
Syntax
( VALUES ( expression [, ...] ) [, ...] )
[ [ AS ] alias [ ( column_alias [, ...] ) ] ]
Examples
The following SQL query reads three rows from a VALUES list with the columns id and name.
SELECT id, name FROM (VALUES (1, 'a'), (2, 'b'), (3, NULL) ) AS t(id, name) ORDER BY id
The query returns the following results.
| id | name |
|---|---|
|
|
|
|
|
|
The following SQL query leaves out the column names, so the columns are named col0 and col1.
SELECT col0, col1 FROM (VALUES (1, 'a'), (2, 'b')) ORDER BY col0
The query returns the following results.
| col0 | col1 |
|---|---|
|
|
|
|
Considerations
Put parentheses around every row, including rows with one value: write VALUES (1), (2), not VALUES 1, 2.