Обсуждение: calling function , passing OLD as argument

Поиск
Список
Период
Сортировка

calling function , passing OLD as argument

От
R.Welz
Дата:
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 'DECLAREresult 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);