plpgsql function question - Mailing list pgsql-novice

From Scott Geller
Subject plpgsql function question
Date
Msg-id h2ic598163c1004032219hbd347706o4e424bf515ce2e71@mail.gmail.com
Whole thread Raw
Responses Re: plpgsql function question
List pgsql-novice

Hi

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;

Any insight would be appreciated!

Thanks

Scott

pgsql-novice by date:

Previous
From: Mladen Gogala
Date:
Subject: Re: slow plan on join when adding where clause
Next
From: Andreas Kretschmer
Date:
Subject: Re: plpgsql function question