pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philippe Rochat (RSR: 318 17 93) <prochat@lbdsun.epfl.ch>
To: pierre@desertmoon.com
To: pgsql-sql@postgresql.org
Subject: Re: Triggers and SQL functions
Date: Sat, 17 Oct 1998 00:38:26 +0200
Message-ID: <3627CAE2.BB7E1F9D@lbdsun.epfl.ch> (raw)
References: <19981016211726.2888.qmail@desertmoon.com>

pierre@desertmoon.com wrote:
> 
> >
> > I have exactly the same problem as you mentioned in a mail
> > sent to postgres mailing lists about creating trigger using
> > sql function ...
> >
> > Did you get the solution to you problem ?
> >
> > Ph.R.
> >
> >
> 
> I actually found the solution in the docs. The solution is to understand
> the difference between triggers and rules. Triggers are used primarily
> to call C/C++ library functions that you can create and add onto the
> postgresql system.
> 
> Rules on the other-hand act just like 'triggers' but only call/usr
> sql to perform their functions.
> 
> So the solution: Use rules to create trigger-like actions that run
> stored sql procedures. There is a man page on 'create rule' that you
> can use to get more info.
> 
> -=pierre
I found out the following trick ... but I m not sure it s clean !

-- Makes all user at least belonging to Void ... just in case
CREATE FUNCTION adduservoid () returns boolean
 as 'insert into user_realm 
        select id as uid,1 as rlid,false as adminuser
        from user where not exists (
           select uid from user_realm where user.id=user_realm.uid
        );
     select true as ignore_this;'
 language 'sql';
CREATE RULE autoadduservoid as
	on insert to user
	do select adduservoid();

Ph.R.

-- 
_____________________________________________________________________
Philippe Rochat,				EPFL   DI-LBD
Database Laboratory 				CH-1015 LAUSANNE
Swiss Federal Institute of Technology (EPFL) 	tel:++41 21 693 52 53
Beep-EPFL: 181 4644				fax:++41 21 693 51 95
Private: Grammont, 9 1007 LAUSANNE 		tel:++41 21 617 03 05 
mailto:Philippe.Rochat@epfl.ch, http://lbdwww.epfl.ch/~prochat



view thread (3+ messages)

Message-ID: <3627CAE2.BB7E1F9D@lbdsun.epfl.ch>
Permalink:  ../3627CAE2.BB7E1F9D@lbdsun.epfl.ch/
Also on:    postgresql.org/message-id/3627CAE2.BB7E1F9D@lbdsun.epfl.ch

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: prochat@lbdsun.epfl.ch, pierre@desertmoon.com
  Subject: Re: Triggers and SQL functions
  In-Reply-To: <3627CAE2.BB7E1F9D@lbdsun.epfl.ch>
  References: <19981016211726.2888.qmail@desertmoon.com> <3627CAE2.BB7E1F9D@lbdsun.epfl.ch>

* 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