Re: [GENERAL] DB insert Error - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: [GENERAL] DB insert Error
Date
Msg-id 20060816173841.GA72967@winnie.fuhr.org
Whole thread Raw
In response to DB insert Error  ("Jasbinder Bali" <jsbali@gmail.com>)
List pgsql-novice
On Wed, Aug 16, 2006 at 02:59:23AM -0400, Harpreet Dhaliwal wrote:
> I mean can we call a stored procedure as an action of a trigger?

You'll need to write a trigger function that calls the non-trigger
function (what you're referring to as "stored procedure").  Example:

CREATE FUNCTION trigger_function() RETURNS trigger AS $$
BEGIN
    PERFORM other_function();
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER trigger_name BEFORE INSERT OR UPDATE ON table_name
  FOR EACH ROW EXECUTE PROCEDURE trigger_function();

> Its actually something like the trigger should start a C function after
> insert and the C function has the ECPG code for some more inserts.
> Its similar to the way we dynamically load a shared library while
> executing a stored procedure, as in , executing a fucntion in C file using
> stored procedure/ function.

You have a server-side C function that uses ECPG?  Is there a reason
you're not using SPI?  Are you connecting to a different server?
Or by "function" do you really mean "program," meaning a separate
executable?

http://www.postgresql.org/docs/8.1/interactive/spi.html

--
Michael Fuhr

pgsql-novice by date:

Previous
From: Keith Worthington
Date:
Subject: Re: COPY command
Next
From: "Jasbinder Bali"
Date:
Subject: Re: [GENERAL] DB insert Error