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 7E3F9D1B170 for ; Sat, 24 Jul 2004 13:13:25 -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 49654-03 for ; Sat, 24 Jul 2004 16:13:21 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 97260D1B1D1 for ; Sat, 24 Jul 2004 13:13:19 -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 i6OGDJla004811; Sat, 24 Jul 2004 12:13:19 -0400 (EDT) To: Andreas Haumer Cc: pgsql-sql@postgresql.org Subject: Re: Trigger functions with dynamic SQL In-reply-to: <41028459.6030002@xss.co.at> References: <410272AD.9010100@xss.co.at> <4370.1090681307@sss.pgh.pa.us> <41028459.6030002@xss.co.at> Comments: In-reply-to Andreas Haumer message dated "Sat, 24 Jul 2004 17:46:33 +0200" Date: Sat, 24 Jul 2004 12:13:19 -0400 Message-ID: <4810.1090685599@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/213 X-Sequence-Number: 18465 Andreas Haumer writes: > I just can't figure out where and how many quotation marks > I have to place in my function. It's messy all right. The "dollar quoting" feature in 7.5 should make it a lot less painful, since you can stop having to double and re-double quote marks. If you're interested in using beta-quality code, you can have that today. An example would go something like CREATE FUNCTION mytrigger() RETURNS trigger AS $PROC$ DECLARE ... EXECUTE $$ SELECT ... FROM $$ || tgargv[0] || $$ WHERE col = 'key' $$; ... END $PROC$ LANGUAGE plpgsql; Here I've used minimal dollar quotes ($$) for the literal constant parts of the EXECUTE'd query, which allows me not to have to double the quote marks that I actually want in the query text (the ones around "key"). And I used dollar quotes with a label ($PROC$) at the outermost level to quote the entire function body, so that there's no conflict with the embedded dollar quotes. In 7.4 the same EXECUTE command would have to be written EXECUTE '' SELECT ... FROM '' || tgargv[0] || '' WHERE col = ''''key'''' ''; which is already getting painful, and more complex cases get rapidly worse. With dollar quoting you can write the constant parts of your query the same way you normally would. > What about writing trigger functions in C? Seems like the hard way to me. I doubt it would be better than plpgsql, but it's all a matter of opinion... regards, tom lane