pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John DeSoi <desoi@pgedit.com>
To: Aaron Bono <postgresql@aranya.com>
Cc: Thusitha Kodikara <kthusi@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Triggers using PL/pgSQL
Date: Mon, 31 Jul 2006 08:17:19 -0400
Message-ID: <7F7548C8-249E-44E2-8205-6C055671DA19@pgedit.com> (raw)
In-Reply-To: <bf05e51c0607302152k2801caflc9040d99af7b2816@mail.gmail.com>
References: <20060731041644.32247.qmail@web56610.mail.re3.yahoo.com>
	<bf05e51c0607302152k2801caflc9040d99af7b2816@mail.gmail.com>

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




view thread (10+ messages)  latest in thread

Message-ID: <7F7548C8-249E-44E2-8205-6C055671DA19@pgedit.com>
Permalink:  ../7F7548C8-249E-44E2-8205-6C055671DA19@pgedit.com/
Also on:    postgresql.org/message-id/7F7548C8-249E-44E2-8205-6C055671DA19@pgedit.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: desoi@pgedit.com, postgresql@aranya.com, kthusi@yahoo.com
  Subject: Re: Triggers using PL/pgSQL
  In-Reply-To: <7F7548C8-249E-44E2-8205-6C055671DA19@pgedit.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox