X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id ACA45D1B1C7 for ; Wed, 14 Jul 2004 21:23:15 -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 96555-07 for ; Thu, 15 Jul 2004 00:23:10 +0000 (GMT) Received: from mail.gmx.net (imap.gmx.net [213.165.64.20]) by svr1.postgresql.org (Postfix) with SMTP id 53C28D1B16E for ; Wed, 14 Jul 2004 21:23:05 -0300 (ADT) Received: (qmail 10814 invoked by uid 65534); 15 Jul 2004 00:23:08 -0000 Received: from D922e.d.pppool.de (EHLO [192.168.1.110]) (80.184.146.46) by mail.gmx.net (mp009) with SMTP; 15 Jul 2004 02:23:08 +0200 X-Authenticated: #22309062 Mime-Version: 1.0 (Apple Message framework v618) Content-Transfer-Encoding: 7bit Message-Id: <24767014-D5F5-11D8-A3E8-0003936EF152@gmx.de> Content-Type: text/plain; charset=US-ASCII; format=flowed To: pgsql-sql@postgresql.org From: R.Welz Subject: calling function , passing OLD as argument Date: Thu, 15 Jul 2004 02:23:06 +0200 X-Mailer: Apple Mail (2.618) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/90 X-Sequence-Number: 18342 Hello. I am a beginner with pgsql and struggeling with the documentation. With the help from the folks on the PSQL Novice List I managed to work out that declaring CREATE OR REPLACE FUNCTION deny_namen_telefonverweise(namen_telefonverweise) RETURNS void AS ' DECLARE ... would work where the function at the bottom fails with test=# \i '/home/myAccount/Documents/Datenbank Layout/Postgres Sytax/test/Regeln2' CREATE FUNCTION psql:/home/myAccount/Documents/Datenbank Layout/Postgres Sytax/test/Regeln2:16: ERROR: function deny_namen_telefonverweise(namen_telefonverweise) does not exist HINT: No function matches the given name and argument types. You may need to add explicit type casts. test=# But I have lots of these functions since I have lots of tables, so what I really want is one function reusable for all parameters which are tables. Question: Would it be possible to pass the table name to the function as variable and EXECUTE then the action I want the function to do? How would I convert OLD to the table name old refers to? Is there another way of letting the function know on which row the rule was called? CREATE OR REPLACE FUNCTION deny_namen_telefonverweise(record) RETURNS void AS ' DECLARE result RECORD; BEGIN /* DELETE ROW LATER */ SELECT 1+1; END; ' LANGUAGE 'plpgsql'; CREATE OR REPLACE RULE deny_namen_Telefonverweise AS ON DELETE TO Namen_Telefonverweise DO INSTEAD SELECT DENY_Namen_Telefonverweise(OLD);