Skip site navigation (1) Skip section navigation (2)

PL/pgSQL and new table creation

From: Matthew Syvinski <matthew(at)techcelsior(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: PL/pgSQL and new table creation
Date: 2004-02-05 01:13:02
Message-ID: 4021989E.5030002@techcelsior.com (view raw or flat)
Thread:
Lists: pgsql-novice
I am looking to automate and simplify the creation of new, empty tables 
from a template.

I'm running PostgreSQL 7.3.4 under Fedora Core 1.

My code:

CREATE OR REPLACE FUNCTION sp_newtable(TEXT) RETURNS VOID AS '

DECLARE

      newtable ALIAS FOR $1;

BEGIN

      SELECT * INTO newtable FROM d_master WHERE False;
      RETURN;

END;

'
LANGUAGE 'plpgsql';

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

Any tips?  I've hammered on this thing for awhile now...

Thanks

Responses

pgsql-novice by date

Next:From: Rob MosherDate: 2004-02-05 02:33:28
Subject: Re: Inserting a Null date.
Previous:From: BantamessDate: 2004-02-04 17:51:44
Subject: Dual Primary Keys

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group