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: 4370.1090681307@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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

Responses

Browse pgsql-sql by date

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