sql – 如何在Amazon Redshift中选择多行填充常量?

我已经尝试过常见的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;

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...