Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql Case when或if then控制红移中的表创建_Postgresql_Amazon Redshift - Fatal编程技术网

Postgresql Case when或if then控制红移中的表创建

Postgresql Case when或if then控制红移中的表创建,postgresql,amazon-redshift,Postgresql,Amazon Redshift,我有一些数据源,我希望对它们应用相同的分析,并最终加载到更大的表数据库中(uniformtable)。不同的源包含不同的列,有时源涉及我需要加入的交叉路径文件。我希望有一个查询,根据每个源的唯一键,将所有源的数据转换为uniformtable格式。大致如下: case when source.sourceid = 1 then create uniformtable as select column1a as uniforma, column1b as uniformb, sourceid f

我有一些数据源,我希望对它们应用相同的分析,并最终加载到更大的表数据库中(
uniformtable
)。不同的源包含不同的列,有时源涉及我需要加入的交叉路径文件。我希望有一个查询,根据每个源的唯一键,将所有源的数据转换为
uniformtable
格式。大致如下:

case when source.sourceid = 1 then
create uniformtable as 
select column1a as uniforma, column1b as uniformb, sourceid from source
else
when source.sourceid = 2 then
create uniformtable as
select column2a as uniforma, column2b as uniformb, sourceid from source
end;

我曾尝试使用if-then和case-when来完成这项工作,但在查询开始时出现语法错误。红移是否允许您将if逻辑用于此类控制?

否,不允许使用此逻辑

CASE
语句仅在
SELECT
语句中有效

您需要在AmazonRedshift外部执行此逻辑,然后只发送最后的SQL来创建表