Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id D9FDF47687B for ; Wed, 13 Nov 2002 07:09:19 -0500 (EST) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by postgresql.org (Postfix) with SMTP id E15AF47687A for ; Wed, 13 Nov 2002 07:09:18 -0500 (EST) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Wed Nov 13 13:09:16 2002 +0100 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id NAA12578; Wed, 13 Nov 2002 13:09:15 +0100 (MET) Message-ID: <3DD240EB.3FD87862@rodos.fzk.de> Date: Wed, 13 Nov 2002 13:09:15 +0100 From: Christoph Haller X-Mailer: Mozilla 4.06 [en] (X11; I; HP-UX B.10.20 9000/780) MIME-Version: 1.0 To: lud_nowhere_man@yahoo.com Cc: pgsql-sql@postgresql.org Subject: Re: Passing OLD/NEW as composite type PL/PGSQL Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/204 X-Sequence-Number: 10346 > > Can I pass the the variables OLD and NEW (type > OPAQUE) to another function is expecting a composite > type as parameter? > > Are opaque considered as composite type? > Did you receive any other response? Did you check if it works by simply trying? As far as I understand the documentation, OPAQUE can be considered (among others) as composite type. If it's not working, did you think of copying the OLD resp. NEW to a rowtype variable? I am thinking of something like this (taken from the Trigger Procedure Example within the documentation) CREATE TABLE emp ( empname text, salary integer, last_date timestamp, last_user text ); CREATE FUNCTION process_old_emp_row(emp%ROWTYPE) RETURNS ... ; CREATE FUNCTION process_new_emp_row(emp%ROWTYPE) RETURNS ... ; CREATE FUNCTION emp_stamp () RETURNS OPAQUE AS ' DECLARE old_emp_row emp%ROWTYPE; new_emp_row emp%ROWTYPE; BEGIN -- copy OLD to old_emp_row, call process_old_emp_row old_emp_row.empname := OLD.empname; old_emp_row.salary := OLD.salary; old_emp_row.last_date := OLD.last_date; old_emp_row.last_user := OLD.last_user; process_old_emp_row(old_emp_row); -- Check that empname and salary are given IF NEW.empname ISNULL THEN RAISE EXCEPTION ''empname cannot be NULL value''; END IF; IF NEW.salary ISNULL THEN RAISE EXCEPTION ''% cannot have NULL salary'', NEW.empname; END IF; -- Who works for us when she must pay for? IF NEW.salary < 0 THEN RAISE EXCEPTION ''% cannot have a negative salary'', NEW.empname; END IF; -- Remember who changed the payroll when NEW.last_date := ''now''; NEW.last_user := current_user; -- copy NEW to new_emp_row, call process_new_emp_row new_emp_row.empname := NEW.empname; new_emp_row.salary := NEW.salary; new_emp_row.last_date := NEW.last_date; new_emp_row.last_user := NEW.last_user; process_new_emp_row(new_emp_row); RETURN NEW; END; ' LANGUAGE 'plpgsql'; Regards, Christoph