Postgresql CREATE TABLE AS INSERT RETURNING

时间:2014-03-06 08:37:05

标签: postgresql plpgsql create-table sql-returning

我尝试执行类似

的操作
CREATE TEMP TABLE tblname AS (
  INSERT INTO tbl2 FROM SELECT(1,1) RETURNING a,b 
);

但是我有错误:语法错误在“INSERT”或附近;

是否可以将 CREATE TABLE AS SELECT INSERT FROM SELECT RETURNING 条款结合起来?

1 个答案:

答案 0 :(得分:9)

create temp table tblname as
    with i as (
        insert into tbl2 (a, b)
        select 1, 1
        returning a,b 
    )
    select a, b
    from i