概要
VALUES row [, ...]
其中, `row`是一个表达式,或者是如下形式的表达式列表:
( column_expression [, ...] )
描述
定义一张字面内联表。
任何可以使用查询语句的地方都可以使用VALUES, 如放在SELECT语句的FROM后面,放在INSERT里,甚至放在最顶层。
VALUES默认创建一张匿名表,并且没有列名。表名和列名可以通过AS进行命名。
presto:default> values 1, 2, 3;
_col0
-------
1
2
3
(3 rows)
presto:default> values (1, 'a'), (2, 'b'), (3, 'c');
_col0 | _col1
-------+-------
1 | a
2 | b
3 | c
(3 rows)
presto:default> values (array[1, 2], array[2, 4]), (array[1, 3], array[2, 6]);
_col0 | _col1
--------+--------
[1, 2] | [2, 4]
[1, 3] | [2, 6]
(2 rows)
presto:default> values (array[1, 2], '1+2=3'), (array[1, 3], '1+3=4');
_col0 | _col1
--------+-------
[1, 2] | 1+2=3
[1, 3] | 1+3=4
(2 rows)
presto:default> select * from (values 1, 2, 3) as t (id);
id
----
1
2
3
(3 rows)
presto:default> select * from (values (1, 'a'), (2, 'b'), (3, 'c')) as t (id, word);
id | word
----+------
1 | a
2 | b
3 | c
(3 rows)
presto:default> select
-> *
-> from (
-> values 3
-> ) as t (id)
-> cross join (
-> values 1, 2, 3
-> ) as t (num);
id | num
----+-----
3 | 1
3 | 2
3 | 3
(3 rows)
presto:default> select
-> *
-> from (
-> values 3
-> ) as t (id)
-> cross join unnest(
-> array[1, 2, 3]
-> ) as t (num);
id | num
----+-----
3 | 1
3 | 2
3 | 3
(3 rows)