我已经尝试过常见的Postgresql答案,但似乎它不适用于Redshift:
SELECT * FROM VALUES (1) AS q (col1); ERROR: 42883: function values(integer) does not exist
我需要这个,因为出于某种原因我不能使用UNION ALL.任何帮助将不胜感激.
解决方法
正确的Postgres语法是:
SELECT * FROM (VALUES (1)) AS q (col1);
缺少一组括号.
但似乎Redshift甚至不支持INSERT之外的VALUES表达式(就像现代的Postgres一样).所以,对于单行:
SELECT * FROM (SELECT 1) AS q (col1);
对于多行(不使用UNION ALL,如请求),您可以使用临时表.注(per documentation):
A temporary table is automatically dropped at the end of the session
in which it was created.
CREATE TEMP TABLE q(col1 int); INSERT INTO q(col1) VALUES (1),(2),(3); SELECT * FROM q;
如果UNION ALL是一个选项:
SELECT 1 AS col1 UNION ALL SELECT 2 UNION ALL SELECT 3;