pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: R.Welz <linuxprodukte@gmx.de>
To: pgsql-sql@postgresql.org
Subject: calling function , passing OLD as argument
Date: Thu, 15 Jul 2004 02:23:06 +0200
Message-ID: <24767014-D5F5-11D8-A3E8-0003936EF152@gmx.de> (raw)

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




Message-ID: <24767014-D5F5-11D8-A3E8-0003936EF152@gmx.de>
Permalink:  ../24767014-D5F5-11D8-A3E8-0003936EF152@gmx.de/
Also on:    postgresql.org/message-id/24767014-D5F5-11D8-A3E8-0003936EF152@gmx.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: linuxprodukte@gmx.de
  Subject: Re: calling function , passing OLD as argument
  In-Reply-To: <24767014-D5F5-11D8-A3E8-0003936EF152@gmx.de>
  References: <24767014-D5F5-11D8-A3E8-0003936EF152@gmx.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox