X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7DB0CDAFD8 for ; Wed, 26 Oct 2005 23:47:54 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10158-03 for ; Thu, 27 Oct 2005 02:47:48 +0000 (GMT) Received: from pd2mo3so.prod.shaw.ca (shawidc-mo1.cg.shawcable.net [24.71.223.10]) by svr1.postgresql.org (Postfix) with ESMTP id 1BE95DAFBD for ; Wed, 26 Oct 2005 23:47:50 -0300 (ADT) Received: from pd4mr2so.prod.shaw.ca (pd4mr2so-qfe3.prod.shaw.ca [10.0.141.213]) by l-daemon (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) with ESMTP id <0IOZ00MOUZRTET20@l-daemon> for pgsql-general@postgresql.org; Wed, 26 Oct 2005 20:47:53 -0600 (MDT) Received: from pn2ml2so.prod.shaw.ca ([10.0.121.146]) by pd4mr2so.prod.shaw.ca (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) with ESMTP id <0IOZ00ECWZRT48M0@pd4mr2so.prod.shaw.ca> for pgsql-general@postgresql.org; Wed, 26 Oct 2005 20:47:53 -0600 (MDT) Received: from OWNER (S0106000d560caa0f.ok.shawcable.net [24.67.29.172]) by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 2003)) with SMTP id <0IOZ0034DZRRMO@l-daemon> for pgsql-general@postgresql.org; Wed, 26 Oct 2005 20:47:53 -0600 (MDT) Date: Wed, 26 Oct 2005 19:47:51 -0700 From: Bob Pawley Subject: Re: Error Message To: Michael Fuhr , Terry Lee Tucker Cc: Postgre General Message-id: <001601c5daa0$d2e717f0$ac1d4318@OWNER> MIME-version: 1.0 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Mailer: Microsoft Outlook Express 6.00.2900.2180 Content-type: text/plain; reply-type=original; charset=iso-8859-1; format=flowed Content-transfer-encoding: 7bit X-Priority: 3 X-MSMail-priority: Normal References: <03a301c5da6e$a20b6280$ac1d4318@OWNER> <11706.1130361821@sss.pgh.pa.us> <041401c5da84$7429ec90$ac1d4318@OWNER> <200510261945.19824.terry@esc1.com> <20051027010006.GA59813@winnie.fuhr.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.308 required=5 tests=[AWL=-0.492, DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376, FORGED_RCVD_HELO=0.05] X-Spam-Level: * X-Archive-Number: 200510/1686 X-Sequence-Number: 85914 I have a base table called "process". Each row of this table is anchored by a serial column labeled "fluid_id". After data has been entered into a row in "process", I want to trigger a row in another table labeled "specification" also with a column labeled "fluid_id". I would like this number from "process" entered into "specification" as an integer. I would like this to happen after each row in "process" has satisfied the not null requirements. I may not be employing the language you are use to using however, I hope this explanation is somewhat clear. Thanks for your help. Bob ----- Original Message ----- From: "Michael Fuhr" To: "Terry Lee Tucker" Cc: "Postgre General" Sent: Wednesday, October 26, 2005 6:00 PM Subject: Re: [GENERAL] Error Message > On Wed, Oct 26, 2005 at 07:45:19PM -0400, Terry Lee Tucker wrote: >> You cannot pass argments to trigger functions. You can to other types of >> functions, but not functions used as triggers. Arguments are passed >> regarding >> the old and new records and other built in variables regarding what kind >> of >> operation is going on, but all of that is "unseen". >> >> They must be created as in: >> CREATE TRIGGER trig1 AFTER INSERT >> ON process FOR EACH ROW >> EXECUTE PROCEDURE base(); >> ^^^^^^ >> Note: no argument. > > You *can* pass arguments to trigger functions but it's done a little > differently than with non-trigger functions. The function must be > defined to take no arguments; it reads the arguments from a context > structure instead of in the normal way. PL/pgSQL trigger functions, > for example, read their arguments from the TG_ARGV array. > > http://www.postgresql.org/docs/8.0/interactive/plpgsql-trigger.html > http://www.postgresql.org/docs/8.0/interactive/trigger-interface.html > > Example: > > CREATE TABLE foo (id integer, x integer); > > CREATE FUNCTION func() RETURNS trigger AS $$ > BEGIN > NEW.x := TG_ARGV[0]; > RETURN NEW; > END; > $$ LANGUAGE plpgsql; > > CREATE TRIGGER footrig BEFORE INSERT OR UPDATE ON foo > FOR EACH ROW EXECUTE PROCEDURE func(12345); > > INSERT INTO foo (id) VALUES (1); > > SELECT * FROM foo; > id | x > ----+------- > 1 | 12345 > (1 row) > > However, it's not clear if this is what Bob is trying to do. His > original attempt was: > >> CREATE TRIGGER trig1 AFTER INSERT >> ON process FOR EACH ROW >> EXECUTE PROCEDURE base(int4); > > He's given what looks like a function signature instead of passing > an argument. Even if this worked, he hasn't specified what argument > should be passed. Bob, can you explain what you're trying to do? > > -- > Michael Fuhr > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org