【发布时间】:2016-06-16 12:55:18
【问题描述】:
如果表不存在,我想根据 PostgreSQL 9.2 中的 select 语句创建一个表。当我使用以下查询时,我收到如下所述的错误。
查询:
CREATE TABLE IF NOT EXISTS ccdb_archival.bills
SELECT *, now() AS archival_date
FROM ccdb.bills
WHERE bill_date::date >= current_date - interval '3 years' AND bill_date::date < current_date - interval '8 years';
错误:
ERROR: syntax error at or near "SELECT"
LINE 2: SELECT *, now() AS archival_date
有人可以建议我如何实现这一目标。
【问题讨论】:
-
您可以升级到 9.5。该版本增加了使用
if not exists和create table as select的可能性 -
在 9.2 中还有其他方法吗?
-
看看this
-
除了旧表中的现有列之外,我还需要新表中的一个额外列。