X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DFCF4D1B23C for ; Sat, 24 Jul 2004 12:01:53 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28403-04 for ; Sat, 24 Jul 2004 15:01:49 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id BD386D1B182 for ; Sat, 24 Jul 2004 12:01:48 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i6OF1lOY004371; Sat, 24 Jul 2004 11:01:47 -0400 (EDT) To: Andreas Haumer Cc: pgsql-sql@postgresql.org Subject: Re: Trigger functions with dynamic SQL In-reply-to: <410272AD.9010100@xss.co.at> References: <410272AD.9010100@xss.co.at> Comments: In-reply-to Andreas Haumer message dated "Sat, 24 Jul 2004 16:31:09 +0200" Date: Sat, 24 Jul 2004 11:01:47 -0400 Message-ID: <4370.1090681307@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/211 X-Sequence-Number: 18463 Andreas Haumer 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