I am learning plpgsql and am getting errors on this simple function:
CREATE OR REPLACE FUNCTION test2(tab1 text, tab2 text ) RETURNS text AS $$ BEGIN EXECUTE 'create table ' || quote_ident(tab2) || ' as Select * from ' || quote_ident(tab1); RETURN 'done'; END; $$ LANGUAGE 'plpgsql' VOLATILE;
Yet, when I replace tab1 & tab2 in the execute statement it works just fine:
CREATE OR REPLACE FUNCTION test2(tab1 text, tab2 text ) RETURNS text AS $$ BEGIN EXECUTE 'create table ' || quote_ident($2) || ' as Select * from ' || quote_ident($1); RETURN 'done'; END; $$ LANGUAGE 'plpgsql' VOLATILE;