Snowpark Migration Accelerator: Values¶
描述¶
在查询中创建可立即使用的临时表。有关更多信息,请参阅 Databricks SQL 语言参考 VALUES (https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-values.html)。
您可使用 SELECT 语句的 FROM 子句中的 VALUES 子句定义一组固定值,以创建特定数量的行。(Snowflake SQL 语言参考 VALUES)
语法¶
VALUES {expression | ( expression [, ...] ) } [, ...] [table_alias]
SELECT expression [, ...] [table_alias]
SELECT ...
FROM ( VALUES ( <expr> [ , <expr> [ , ... ] ] ) [ , ( ... ) ] ) [ [ AS ] <table_alias> [ ( <column_alias> [, ... ] ) ] ]
[ ... ]
示例源模式¶
设置数据¶
Databricks¶
CREATE TEMPORARY VIEW number1(c) AS VALUES (3), (1), (2), (2), (3), (4);
Snowflake¶
CREATE TEMPORARY TABLE number1(c int);
INSERT INTO number1 VALUES (3), (1), (2), (2), (3), (4);
模式代码¶
Databricks¶
-- single row, without a table alias
> VALUES ("one", 1);
one 1
-- Multiple rows, one column
> VALUES 1, 2, 3;
1
2
3
-- three rows with a table alias
> SELECT data.a, b
FROM VALUES ('one', 1),
('two', 2),
('three', NULL) AS data(a, b);
one 1
two 2
three NULL
-- complex types with a table alias
> SELECT a, b
FROM VALUES ('one', array(0, 1)),
('two', array(2, 3)) AS data(a, b);
one [0, 1]
two [2, 3]
-- Using the SELECT syntax
> SELECT 'one', 2
one 2
c |
---|
3 |
1 |
2 |
4 |
Snowflake¶
-- single row, without a table alias
SELECT * FROM (VALUES ('one', 1));
-- Multiple rows, one column
SELECT * FROM (VALUES (1), (2), (3));
-- three rows with a table alias
SELECT a, b
FROM (VALUES ('one', 1),
('two', 2),
('three', NULL)) AS data(a, b);
-- complex types with a table alias
SELECT a, b
FROM
(VALUES ('one', '[0, 1]'),
('two', '[2, 3]')
) AS data(a, b);
-- Using the SELECT syntax
SELECT 'one', 2
c |
---|
3 |
1 |
2 |
4 |
已知问题¶
未发现任何问题