Skip site navigation (1) Skip section navigation (2)

Re: [NOVICE] DB insert Error

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Harpreet Dhaliwal <harpreet(dot)dhaliwal01(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org
Subject: Re: [NOVICE] DB insert Error
Date: 2006-08-16 17:38:41
Message-ID: 20060816173841.GA72967@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-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

In response to

pgsql-novice by date

Next:From: Jasbinder BaliDate: 2006-08-16 18:42:46
Subject: Re: [NOVICE] DB insert Error
Previous:From: Tom LaneDate: 2006-08-16 17:14:57
Subject: Re: libpq Describe Extension [WAS: Bytea and perl]

pgsql-general by date

Next:From: Stephan SzaboDate: 2006-08-16 17:44:11
Subject: Re: Weird join result
Previous:From: Jeff DavisDate: 2006-08-16 17:36:54
Subject: Re: Determine Transactions Per Second

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group