如何在 Amazon Redshift 中 select 多行填充常量?

How to select multiple rows filled with constants in Amazon Redshift?

我已经尝试过常见的 PostgreSQL 答案,但似乎不适用于 Redshift:

SELECT  * FROM VALUES (1) AS q (col1);

ERROR: 42883: function values(integer) does not exist

我需要这个,因为出于某种原因我不能使用 UNION ALL。任何帮助将不胜感激。

正确的 Postgres 语法是:

SELECT * FROM <b>(</b>VALUES (1)<b>)</b> AS q (col1);

缺少一组括号。
但似乎 Redshift 甚至不支持 INSERT 之外的 VALUES 表达式(就像现代 Postgres 那样)。所以,对于 单行 :

SELECT * FROM <b>(</b>SELECT 1<b>)</b> AS q (col1);

对于多行(不按要求使用UNION ALL),您可以使用临时table。注(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;