calling function , passing OLD as argument

From: R(dot)Welz <linuxprodukte(at)gmx(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: calling function , passing OLD as argument
Date: 2004-07-15 00:23:06
Message-ID: 24767014-D5F5-11D8-A3E8-0003936EF152@gmx.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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);

Browse pgsql-sql by date

  From Date Subject
Next Message Christopher Browne 2004-07-15 02:44:52 Re: Secure DB Systems - How to
Previous Message Alexander M. Pravking 2004-07-14 18:51:07 Indexable (constant LIKE prefix_keyfield) ?