pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: darthxiong@libero.it
To: pgsql-admin@postgresql.org
Subject: passing argument ro a trigger
Date: Fri, 22 Feb 2002 10:39:02 +0100
Message-ID: <02022210390208.07798@ivan> (raw)

hi all,
i have two tables, the first contains major numbers and their status, the 
second contains major numbers, all their minors, and a action taken over the 
major/minor

table 1
major	status
1	1
2	1
3	1
4	0
5	2
......


table 2
major	minor	action
1	0	2
1	1	0
1	2	1
2	0	4
2	1	0
2	2	2
2	3	2
2	4	1
...

so in the table 1, i have to do so:

CREATE FUNCTION align_status( int4 ) RETURNS int2 AS
'
UPDATE table1 SET status = (
 SELECT action FROM table2
 WHERE major = $1
 AND monir = ( 
  SELECT MAX( monir ) FROM table1 WHERE major = $1 )
 )
WHERE major = $1;
 
SELECT  status FROM table1 AS RESULT WHERE major = $1 ;
'
LANGUAGE 'SQL';
;


this works fine, i have only to pass to this function the value of the major 
to be aligned. I'd like to connect this to a trigger that fires after an 
insert in the table2... eg, i insert 2,5,7 in table2 and status in table1 
status must be updated to 7.
The function require an argument, how can i pass the major number to it 
trought the trigger?

CREATE TRIGGER trigger_align_status
AFTER INSERT ON table2
FOR EACH STATEMENT
EXECUTE PROCEDURE align_status ( UUUAAAAAAAARRGGHHH );

#!/usr/bin/perl 
s/UUAARRGGHH/correct method/ if $you_can ;-)

TIA
Ivan





-- 
Ninety-Ninety Rule of Project Schedules:
	The first ninety percent of the task takes ninety percent of
	the time, and the last ten percent takes the other ninety percent.



view thread (2+ messages)  latest in thread

Message-ID: <02022210390208.07798@ivan>
Permalink:  ../02022210390208.07798@ivan/
Also on:    postgresql.org/message-id/02022210390208.07798@ivan

 · 

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-admin@postgresql.org
  Cc: darthxiong@libero.it
  Subject: Re: passing argument ro a trigger
  In-Reply-To: <02022210390208.07798@ivan>
  References: <02022210390208.07798@ivan>

* 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