Re: Trigger functions with dynamic SQL - Mailing list pgsql-sql

From Tom Lane
Subject Re: Trigger functions with dynamic SQL
Date
Msg-id 4370.1090681307@sss.pgh.pa.us
Whole thread Raw
In response to Trigger functions with dynamic SQL  (Andreas Haumer <andreas@xss.co.at>)
Responses Re: Trigger functions with dynamic SQL
List pgsql-sql
Andreas Haumer <andreas@xss.co.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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Is a backend id or something available for use as a foreign key?
Next
From: Andreas Haumer
Date:
Subject: Re: Trigger functions with dynamic SQL