Postgresql CREATE TABLE AS INSERT RETURNING
Asked Answered
I

1

5

I trying to perform something like

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

but i've got ERROR: syntax error at or near "INSERT";

Is it possible to combine CREATE TABLE AS SELECT and INSERT FROM SELECT RETURNING clauses?

Illailladvised answered 6/3, 2014 at 8:37 Comment(1)
Unrelated, but: there is no need to put the select statement for a create table as in parentheses.Reiko
P
14
create temp table tblname as
    with i as (
        insert into tbl2 (a, b)
        select 1, 1
        returning a,b 
    )
    select a, b
    from i
Peanut answered 6/3, 2014 at 9:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.