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 2083FDAFD8 for ; Wed, 26 Oct 2005 22:00:52 -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 69637-09 for ; Thu, 27 Oct 2005 01:00:48 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id DFEE5DAFD1 for ; Wed, 26 Oct 2005 22:00:49 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j9R107Fh004955 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 26 Oct 2005 19:00:11 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id j9R106Nf059984; Wed, 26 Oct 2005 19:00:06 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id j9R1063N059983; Wed, 26 Oct 2005 19:00:06 -0600 (MDT) (envelope-from mfuhr) Date: Wed, 26 Oct 2005 19:00:06 -0600 From: Michael Fuhr To: Terry Lee Tucker Cc: Postgre General Subject: Re: Error Message Message-ID: <20051027010006.GA59813@winnie.fuhr.org> References: <03a301c5da6e$a20b6280$ac1d4318@OWNER> <11706.1130361821@sss.pgh.pa.us> <041401c5da84$7429ec90$ac1d4318@OWNER> <200510261945.19824.terry@esc1.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200510261945.19824.terry@esc1.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200510/1681 X-Sequence-Number: 85909 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