Re: PL/pgSQL and new table creation

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Matthew Syvinski <matthew(at)techcelsior(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: PL/pgSQL and new table creation
Date: 2004-02-05 03:53:32
Message-ID: 200402041953.32203.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Matt,

> But when I run it, I get the following error.
>
> WARNING: plpgsql: ERROR during compile of sp_newtable near line 8
> ERROR: $1 is declared CONSTANT

You can't use a variable in place of an object name, unless you execute the
query as a dynamic string, e.g.:

CREATE FUNCTION new_table(TEXT) returns INT as
'DECLARE tbname ALIAS for $1;
BEGIN
EXECUTE 'SELECT * INTO ' || newtable || ' FROM d_master';
RETURN 1;
END;' LANGUAGE plpgsql;

--
-Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2004-02-05 05:09:33 Re: Inserting a Null date.
Previous Message Rob Mosher 2004-02-05 02:33:28 Re: Inserting a Null date.