X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 9BFCC9FB1E0 for ; Mon, 31 Jul 2006 09:19:24 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 80651-05 for ; Mon, 31 Jul 2006 09:19:04 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from a2s5.a2hosting.com (host-209-124-50-10.a2webhosting.com [209.124.50.10]) by postgresql.org (Postfix) with ESMTP id 73BCA9FB335 for ; Mon, 31 Jul 2006 09:18:19 -0300 (ADT) Received: from adsl-155-100-31.tys.bellsouth.net ([72.155.100.31] helo=[192.168.1.10]) by a2s5.a2hosting.com with esmtpsa (TLSv1:RC4-SHA:128) (Exim 4.52) id 1G7Wik-0007EV-Dy; Mon, 31 Jul 2006 08:18:06 -0400 In-Reply-To: References: <20060731041644.32247.qmail@web56610.mail.re3.yahoo.com> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <7F7548C8-249E-44E2-8205-6C055671DA19@pgedit.com> Cc: "Thusitha Kodikara" , pgsql-sql@postgresql.org Content-Transfer-Encoding: 7bit From: John DeSoi Subject: Re: Triggers using PL/pgSQL Date: Mon, 31 Jul 2006 08:17:19 -0400 To: Aaron Bono X-Mailer: Apple Mail (2.752.2) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - a2s5.a2hosting.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - pgedit.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.043 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, SPF_HELO_SOFTFAIL, SPF_SOFTFAIL, UPPERCASE_25_50 X-Spam-Level: ** X-Archive-Number: 200607/375 X-Sequence-Number: 25949 Is it really necessary to build a SQL string and use execute? It seems you could just issue the INSERT statement. On Jul 31, 2006, at 12:52 AM, Aaron Bono wrote: > CREATE OR REPLACE FUNCTION my_table_history_fn () RETURNS SETOF > opaque AS > ' > BEGIN > -- if a trigger insert or update operation occurs > IF TG_OP = ''INSERT'' OR TG_OP = ''UPDATE'' THEN > execute > ''INSERT INTO my_table_history ( '' || > '' my_table_id, '' || > '' my_value, '' || > '' create_dt '' || > '') VALUES ( '' || > '' '''''' || NEW.my_table_id || '''''', '' || > '' '''''' || NEW.my_value || '''''', '' || > '' now() '' || > '');'' > ; > RETURN NEW; > END IF; > END; > ' > LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER; John DeSoi, Ph.D. http://pgedit.com/ Power Tools for PostgreSQL