VALUES
Computes a set of rows.
Syntax
VALUES ( <expression> [, ...] ) [, ...]
[ORDER BY <sort_expression> [ ASC | DESC | USING <operator> ] [, ...] ]
[LIMIT { <count> | ALL } ]
[OFFSET <start> [ ROW | ROWS ] ]
[FETCH { FIRST | NEXT } [<count> ] { ROW | ROWS } ONLY ]
Description
VALUES computes a row value or set of row values specified by value expressions. It is most commonly used to generate a "constant table" within a larger command, but it can be used on its own.
If multiple rows are specified, they must all contain the same number of elements. The data types for the resulting table columns are decided by combining the types from the expressions in that column, following the rules used for UNION.
In larger commands, VALUES can be used wherever SELECT is allowed. Because VALUES is treated like SELECT by the grammar, you can use ORDER BY, LIMIT (or FETCH FIRST), and OFFSET clauses with a VALUES command.
Parameters
-
<expression>A constant or expression to compute and insert at the indicated place in the resulting table (set of rows). In a
VALUESlist appearing at the top level of anINSERT, an expression can be replaced byDEFAULTto indicate that the default value of the destination column should be inserted.DEFAULTcannot be used whenVALUESappears in other contexts. -
<sort_expression>An expression or integer constant indicating how to sort the result rows. This expression may refer to the columns of the
VALUESresult ascolumn1,column2, and so on. For more information, see "The ORDER BY Clause" in the parameters for SELECT. -
<operator>A sorting operator. For more information, see "The ORDER BY Clause" in the parameters for SELECT.
-
LIMIT <count>orOFFSET <start>The maximum number of rows to return. For more information, see "The LIMIT Clause" in the parameters for SELECT.
Usage notes
It is recommended that you avoid using VALUES lists with a large number of rows due to the risk of out-of-memory failures or poor performance. The use of VALUES within INSERT commands is an exception. This is because the targeted table of the INSERT provides the desired column types, eliminating the need to infer them by scanning the VALUES list. This allows it to handle larger lists than in other contexts.