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

Re: Trigger functions with dynamic SQL

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andreas Haumer <andreas(at)xss(dot)co(dot)at>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Trigger functions with dynamic SQL
Date: 2004-07-24 15:01:47
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Andreas Haumer <andreas(at)xss(dot)co(dot)at> writes:
> It seems I would have to use EXECUTE on dynamically constructed
> PL/PGSQL statements in order to have my trigger function recognize
> the parameters given to the trigger in TG_ARGV[]

Yup, that's exactly right.  plpgsql isn't designed for this; it's
designed for situations where it can pre-plan and cache plans for
queries, and dynamically-inserted table and column names would just
break that completely.  So you have to fall back to the mechanisms
for fully general constructed-on-the-fly queries, which work but
are a bit painful to use.

You might want to look at pltcl instead, which is much friendlier
to dynamically generated queries (since that's the only way it
does things).  Of course, if you've never used Tcl there'll be
a bit of a learning curve :-(

			regards, tom lane

In response to


pgsql-sql by date

Next:From: Andreas HaumerDate: 2004-07-24 15:46:33
Subject: Re: Trigger functions with dynamic SQL
Previous:From: Tom LaneDate: 2004-07-24 14:39:48
Subject: Re: Is a backend id or something available for use as a foreign key?

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