Received: from rtsystem.com (unknown [217.58.88.227]) by postgresql.org (Postfix) with SMTP id 209B5475914 for ; Fri, 22 Feb 2002 04:39:30 -0500 (EST) Received: (qmail 960 invoked by uid 64014); 22 Feb 2002 09:39:21 -0000 Received: from ivan@rtsystem.com by rtsystem with qmail-scanner-1.03 (fsecure: 4.11/3190/2001-05-14/2001-05-14. 2001-05-11/. Clean. Processed in 0.900074 secs); 22 Feb 2002 09:39:21 -0000 Received: from unknown (HELO ivan) (217.58.88.228) by rtsystem.com with SMTP; 22 Feb 2002 09:39:20 -0000 Content-Type: text/plain; charset="iso-8859-1" From: darthxiong@libero.it To: pgsql-admin@postgresql.org Subject: passing argument ro a trigger Date: Fri, 22 Feb 2002 10:39:02 +0100 X-Mailer: KMail [version 1.2] MIME-Version: 1.0 Message-Id: <02022210390208.07798@ivan> Content-Transfer-Encoding: 8bit X-Archive-Number: 200202/292 X-Sequence-Number: 3445 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.