SELECT .. INTO to create a table in PL/pgSQL
I want to use SELECT INTO to make a temporary table in one of my functions. SELECT INTO works in SQL but not PL/pgSQL. This statement creates a table called mytable (If orig_table exists as a relation): SELECT * INTO TEMP TABLE mytable FROM orig_table; But put this function into PostgreSQL, and you get the error: ERROR: "temp" is not a known variable CREATE OR REPLACE FUNCTION whatever() RETURNS void AS $$ BEGIN SELECT * INTO TEMP TABLE mytable FROM orig_table; END; $$ LANGUAGE plpgsql; I can SELECT INTO a variable of type record within PL/pgSQL, but then I have to define the structure when