Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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);


pgsql-sql by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group