X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id BFD9A9FA436 for ; Fri, 18 Aug 2006 22:02:12 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 16714-01 for ; Fri, 18 Aug 2006 22:01:29 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id C1BB49FB2AC for ; Fri, 18 Aug 2006 22:01:29 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.7/8.13.7) with ESMTP id k7J11L01023971 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 18 Aug 2006 19:01:24 -0600 (MDT) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.6/8.13.6) with ESMTP id k7J11LXd086646; Fri, 18 Aug 2006 19:01:21 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.6/8.13.6/Submit) id k7J11LFU086645; Fri, 18 Aug 2006 19:01:21 -0600 (MDT) (envelope-from mfuhr) Date: Fri, 18 Aug 2006 19:01:21 -0600 From: Michael Fuhr To: Jacobo =?iso-8859-1?Q?Garc=EDa?= Cc: pgsql-sql@postgresql.org Subject: Re: trigger needs to check in multiple tables. Message-ID: <20060819010121.GA86524@winnie.fuhr.org> References: <5f867bd20608181017u2ccf8db7o12338bbbe66977fb@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5f867bd20608181017u2ccf8db7o12338bbbe66977fb@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.263 tagged_above=0 required=5 tests=AWL, SPF_PASS X-Spam-Level: X-Archive-Number: 200608/145 X-Sequence-Number: 26103 On Fri, Aug 18, 2006 at 07:17:27PM +0200, Jacobo Garca wrote: > I'm running a simple query inside a function that is associated with a > trigger: > > SELECT tipo INTO tipocuenta FROM producto WHERE codigo_cuenta= > NEW.codigo_destino; > > I am getting this error when running the code on pgadmin III > > ERROR: NEW used in query that is not in a rule > QUERY: SELECT tipo FROM producto WHERE codigo_cuenta=NEW.codigo_destino Trigger functions must return TRIGGER; the function you posted returns BOOLEAN. If you change the return type to TRIGGER then the above error should go away. However, the function also has several syntax errors. > ELSIF (NOT op=11 OR NOT op=12) The above line and a few others are missing THEN. > SELECT cantidad INT imp FROM movimiento WHERE codigo => NEW.codigo; INT should be INTO. > RAISE EXCEPTION 'Se ha de transferir todo el saldo de la cuenta' This line is missing a trailing semicolon. > oficinacorrecta(NEW.codigo,NEW.codigo_oficina); Use PERFORM to call a function for its effects and ignore its return value. Or did you mean to assign the return value to a variable? > ENDIF; ENDIF should be END IF. If you make the indicated changes then the function should be created successfully. I didn't look closely at the logic, so whether it'll actually work is another matter ;-) -- Michael Fuhr