- Categories:
VALUES¶
In the SELECT statement, the VALUES subclause of the FROM clause lets you specify a set of constants to form a finite set of rows.
For information about the VALUES clause in the INSERT statement, see the documentation for the INSERT statement.
Syntax¶
Parameters¶
exprEach expression must be a constant, or an expression that can be evaluated as a constant during compilation of the SQL statement.
Most simple arithmetic expressions and string functions can be evaluated at compile time, but most other expressions can’t.
table_aliasAn optional alias to give the set of rows a name, as though the set of rows were a table.
column_aliasOptional column aliases can specify the columns names.
Usage notes¶
Inside a FROM clause, a VALUES clause can’t contain the
DEFAULTkeyword. This limitation is in contrast to a VALUES clause in an INSERT statement, which supports the use ofDEFAULT; for example,INSERT INTO table VALUES (10, DEFAULT, 'Name') ....When a VALUES clause includes multiple values of different data types for the same column, Snowflake determines a common data type that can encompass all values and implicitly converts each value to that common type. This conversion can produce unexpected results or errors if you aren’t aware of it.
To avoid unexpected coercion, explicitly CAST each value to the desired type, separate the values into multiple SQL statements, or ensure that all values in a column share the same type.
Numeric example
When numeric values in the same column differ significantly in scale or precision, Snowflake might return an
out of rangeerror because a value doesn’t fit in the determined common numeric type.For numeric values specifically, you can also specify values as text strings in quotation marks and then convert them to numeric values as needed.
Timestamp example
When timestamp values of different types appear in the same column, Snowflake converts all values to a common timestamp type. In the following example, a TIMESTAMP_NTZ value is coerced to TIMESTAMP_LTZ:
The VALUES clause is limited to 200,000 rows.
Examples¶
The following examples use the VALUES clause to generate a fixed, known set of rows:
You can reference values either by column name (implicit) or column position. The following example references the second column by column position:
The following example distinguishes multiple VALUES clauses by using aliases:
You can also specify aliases for the column names, as shown in the following example: