Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id EE7664758D7 for ; Wed, 21 Aug 2002 03:35:33 -0400 (EDT) Received: from bung.cention.se (xaero.cention.se [212.75.78.130]) by postgresql.org (Postfix) with ESMTP id A8FC7475828 for ; Wed, 21 Aug 2002 03:35:32 -0400 (EDT) Received: from andreas ([212.75.90.105]) by bung.cention.se (8.11.6/8.11.6) with SMTP id g7L7Vob07066 for ; Wed, 21 Aug 2002 09:31:50 +0200 From: "Andreas Johansson" To: Subject: Trigger/Function problem Date: Wed, 21 Aug 2002 09:34:20 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Importance: Normal X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/302 X-Sequence-Number: 9148 Hi all, I have a slight problem using triggers and functions in PostGreSQL. I'm currently running PostGreSQL 7.2.1 on a RedHat 7.2. I've compiled the sources (no rpm installation). I have several different tables and in each table there's a status flag that's telling if a row is deleted or not (I don't actually want to delete the rows). Here are my tables (simplified). Site: id serial name char(120) status int Page: id serial name char(120) status int site_id int Text: id serial name char(120) status int page_id int Now to my problem. What I want to do is if I change status in site or page the child items to them should also change. No problem I thought, I'll solve this with a trigger and a function. Did my first test like this: ------- create function fix_status() returns opaque as ' BEGIN IF old.status <> new.status THEN update text set status = new.status where page_id = new.id; END IF; RETURN new; END; ' language 'plpgsql'; CREATE TRIGGER page_status AFTER UPDATE ON pages FOR EACH ROW EXECUTE PROCEDURE fix_status(); ------- Works fine. Now I'd like to add the same thing for the site table. No worries I thought but I don't wont to duplicate the fix_status function so I'll make it take a parameter. ------- create function fix_status(char, char) returns opaque as ' BEGIN IF old.status <> new.status THEN update $1 set status = new.status where $2 = new.id; END IF; RETURN new; END; ' language 'plpgsql'; CREATE TRIGGER page_status AFTER UPDATE ON pages FOR EACH ROW EXECUTE PROCEDURE fix_status('text','page_id'); ------- Then I get the following error: ERROR: CreateTrigger: function fix_status() does not exist Why doesn't the trigger acknowledge that I want to call fix_status with a parameter for which table name I should use? I'm completely stuck and I someone out there can help me. -> Andreas