dbTalk Databases Forums  

rule calls function, passing OLD

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss rule calls function, passing OLD in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
R.Welz
 
Posts: n/a

Default rule calls function, passing OLD - 07-14-2004 , 08:00 AM






Hello.
I am a beginner with pgsql and struggeling with the documentation.

Why can't I pass OLD from my rule to the function so the function knows
on which row the rule was called?


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=#


When I pass an integer instead, everything works.

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


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
  #2  
Old   
Stephan Szabo
 
Posts: n/a

Default Re: rule calls function, passing OLD - 07-14-2004 , 09:26 AM







On Wed, 14 Jul 2004, R.Welz wrote:

Quote:
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.
I'd think you'd want the function declared as above (using the specific
rowtype), not as one taking record, which appears to work for me.

Quote:
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);
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend



Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: rule calls function, passing OLD - 07-14-2004 , 09:29 AM



"R.Welz" <linuxprodukte (AT) gmx (DOT) de> writes:
Quote:
CREATE OR REPLACE FUNCTION deny_namen_telefonverweise(record) RETURNS
void AS '
...
LANGUAGE 'plpgsql';
You can't do that. CVS tip tells you so immediately:
ERROR: plpgsql functions cannot take type record
but I think 7.4 wouldn't notice until you try to execute the function.

You could declare the function as taking the specific rowtype of the
table, though:

CREATE OR REPLACE FUNCTION deny_namen_telefonverweise(Namen_Telefonverweise) RETURNS

Notice that the error message you're getting is specifically complaining
about the lack of such a function.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.