Prepared statment using arrays and temp table

113 Views Asked by At

I am have this temporary table statement:

CREATE TEMP TABLE mytable AS
SELECT UNNEST(ARRAY[1, 2, 3]) AS name, UNNEST(ARRAY['a', 'b', 'c']) AS col2;

From which I am trying to create a prepared statement. As far as I can make out from the Postgres docs, the below should work, but I am getting the below error.

PREPARE createTempTable(int[], text[]) AS
CREATE TEMP TABLE mytable AS
    SELECT UNNEST($1) AS col1, UNNEST($2) AS col2;
EXECUTE createTempTable(ARRAY[1, 2, 3], ARRAY['a', 'b', 'c']);
ERROR:  syntax error at or near "CREATE"
LINE 1: PREPARE createTempTable(int[], text[]) AS CREATE TEMP TABLE ...
0

There are 0 best solutions below