Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 0988B475B86 for ; Tue, 20 Aug 2002 17:59:49 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id 8C6844759A1 for ; Tue, 20 Aug 2002 17:59:48 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 7DCF1D617; Tue, 20 Aug 2002 14:59:50 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 7376F5C04; Tue, 20 Aug 2002 14:59:50 -0700 (PDT) Date: Tue, 20 Aug 2002 14:59:50 -0700 (PDT) From: Stephan Szabo To: Martin Marques Cc: Subject: Re: functions and triggers In-Reply-To: <1029879444.3d62b694112ac@bugs.unl.edu.ar> Message-ID: <20020820145456.F45900-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/300 X-Sequence-Number: 9146 On Tue, 20 Aug 2002, Martin Marques wrote: > Quoting Stephan Szabo : > > > > > > The problemas are two: > > > > > > 1) when I try to create the trigger, it says that the function doesn't > > exist. > > > Why is this happening? > > > > You should probably show us what you were trying to do, but I'm going to > > guess that the function doesn't have the right signature. On > > current versions, Trigger functions should return opaque and take no > > arguments (any arguments given on the create trigger line are passed > > in a different fashion). > > I have this function which works OK. > > CREATE FUNCTION ahora (integer) RETURNS integer AS ' > UPDATE usuarios SET tmodif = now() > WHERE codigo = $1; > SELECT 1 as RESULT; > ' LANGUAGE SQL Trigger functions have no args and return opaque and I don't think you can use sql language functions, but I'm not sure. Something like: create function ahora_trigger() returns opaque as ' begin NEW.tmodif := now(); return NEW; end;' language 'plpgsql'; should work as a before update trigger.