Re: CREATE TABLE problem in plpgsql trigger

From: James Croft <james(dot)croft(at)lumison(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: CREATE TABLE problem in plpgsql trigger
Date: 2005-05-19 17:04:03
Message-ID: 428CC703.9070800@lumison.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Stephan Szabo wrote:

>On Thu, 19 May 2005, James Croft wrote:
>
>
>>Hi all,
>>
>>I'm trying to create a trigger function for a few tables that will store
>>old versions of rows prior to any update on them. Part of the function
>>needs to creates other tables (the table to store these snapshots in).
>>
>>When this trigger runs I get the and error of 'syntax error at or near
>>"$1" at character 15' which is the CREATE TABLE line.
>>
>
>Yes, I don't think support statements like CREATE TABLE currently work
>with variables directly. You probably can use EXECUTE however by
>generating a string containing the command you want to run first.
>
>Something like:
>EXECUTE ''CREATE TABLE '' || snapshottable || '' (LIKE ''
> || originaltable || '')'';
>
>excepting that you'd need to be more careful with quoting.
>

Thanks Stephanm, that fixed it.

--
James Croft
Lumison
t: 0845 1199 911
f: 0845 1199 901
d: 0131 5144 022

Attachment Content-Type Size
james.croft.vcf text/x-vcard 278 bytes

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Matthew Hixson 2005-05-19 17:07:34 Re: 8.0.3 build error on Mac OS X 10.4
Previous Message Bryan Encina 2005-05-19 17:01:22 Re: Postgres in government