amazon-web-services - 在 Redshift 中,如何将 CTAS 与 "if not exists"子句结合使用?

标签 amazon-web-services amazon-redshift

我在让这个表创建查询工作时遇到了一些问题,我想知道我是否遇到了 redshift 的限制。

这是我想做的: 我有需要在模式之间移动的数据,我需要为数据动态创建目标表,但前提是它们尚不存在。

以下是我知道有效的查询:

create table if not exists temp_table (id bigint);

这会创建一个表(如果它尚不存在),并且工作正常。

create table temp_2 as select * from temp_table where 1=2;

这样就创建了一个与前一个结构相同的空表。这也很好。

但是,当我执行此查询时:

create table if not exists temp_2 as select * from temp_table where 1=2;

Redshift 阻塞并说在 as 附近有一个错误(为了记录,我确实尝试删除“as”然后它说在 select 附近有一个错误)

我在 redshift 文档中找不到任何内容,目前我只是在猜测如何解决这个问题。这是我在 redshift 中做不到的事情吗?

我应该提一下,我绝对可以分离出有选择地创建表并用数据填充它的查询,我可能最终会这样做。我只是很好奇是否有人可以告诉我该查询有什么问题。

编辑:

我不认为这是重复的。链接到的帖子提供了许多依赖于用户定义函数的解决方案……redshift 不支持 UDF。他们最近确实实现了一个基于 python 的 UDF 系统,但我的理解是它处于测试阶段,而且我们不知道如何实现它。

谢谢你的关注。

最佳答案

I couldn't find anything in the redshift docs, and at this point I'm just guessing as to how to fix this. Is this something I just can't do in redshift?

事实上 CREATE TABLE ... AS SELECTIF NOT EXISTS 的这种组合在 Redshift 中是不可能的(根据 documentation )。关于 PostgreSQL,从 9.5 版 开始是可能的。

关于 SO,这里讨论:PostgreSQL: Create table if not exists AS .接受的答案提供了不需要任何 UDF 或程序代码的选项,因此它们也可能适用于 Redshift。

关于amazon-web-services - 在 Redshift 中,如何将 CTAS 与 "if not exists"子句结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29303529/

相关文章:

php - 我已经使用 PHP7 开发了一个应用程序,但是在服务器上有 PHP5,我们无法在那里升级 PHP

amazon-web-services - AWS EKS - 集群没有可用于调度 Pod 的节点

mysql - Redshift/MySQL - 检查 2 个整数列之间的不相等返回错误结果

python - Redshift + SQLAlchemy 长查询挂起

amazon-web-services - Spring Boot 和 AWS RDS 只读副本

python - Airflow/Amazon EMR : The VPC/subnet configuration was invalid: Subnet is required : The specified instance type m5. xlarge 只能在VPC中使用

amazon-web-services - Erlang 节点通过 vpn 通信

amazon-web-services - 如何通过SQL Workbench将Amazon Redshift输出保存到本地CSV?

sql - 在 Redshift 中按类别选择 n 个最大计数

amazon-web-services - 如何使用 AWS CLI 在 Redshift 数据库上运行查询