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
begin:vcard fn:James Croft n:Croft;James org:Lumision Ltd adr:;;12 Dock Place;Edinburgh;;EH6 6LU;UK email;internet:james.croft@xxxxxxxxxxx title:Systems Developer tel;work:0131 514 4022 tel;fax:0845 1199 900 x-mozilla-html:TRUE url:http://www.lumison.net version:2.1 end:vcard
---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster