Re: Triggers using PL/pgSQL

From: John DeSoi <desoi(at)pgedit(dot)com>
To: Aaron Bono <postgresql(at)aranya(dot)com>
Cc: "Thusitha Kodikara" <kthusi(at)yahoo(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Triggers using PL/pgSQL
Date: 2006-07-31 12:17:19
Message-ID: 7F7548C8-249E-44E2-8205-6C055671DA19@pgedit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php pgsql-sql

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

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Aaron Bono 2006-07-31 14:59:22 Re: Triggers using PL/pgSQL
Previous Message Devrim GUNDUZ 2006-07-31 07:17:08 Re: How to upgrade Centos 4.3 to PHP 5.1 and Postgresql 8.1

Browse pgsql-sql by date

  From Date Subject
Next Message Aaron Bono 2006-07-31 14:59:22 Re: Triggers using PL/pgSQL
Previous Message Mathieu Arnold 2006-07-31 11:56:18 Re: DBD::Pg ... how would I format this prepare?