Passing tables as parameter

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

Passing tables as parameter

От:
gianpaolo <gianpaolo@preciso.net>
Дата:
Short question:
is it possible to pass tables names as parameter in FUNCTION?
I tried with SQL function as well as with PLPGSQL but I couldn't do it.
Did I do something wrong or is it impossible?
Thanks a lot

	gianpaolo racca
	gianpaolo@preciso.net

Re: Passing tables as parameter

От:
"Robert B. Easter" <reaster@comptechnews.com>
Дата:
Can I see your function that tried to do it?  Pg 7.1 beta has a new EXECUTE 
statement for PL/pgSQL that allows execution of a query string that can be 
created dynamically (see the development docs at www.postgresql.org).  It 
might be relevant to your problem.

On Friday 05 January 2001 03:59, gianpaolo wrote:
> Short question:
> is it possible to pass tables names as parameter in FUNCTION?
> I tried with SQL function as well as with PLPGSQL but I couldn't do it.
> Did I do something wrong or is it impossible?
> Thanks a lot
>
> 	gianpaolo racca
> 	gianpaolo@preciso.net

-- 
-------- Robert B. Easter  reaster@comptechnews.com ---------
-- CompTechNews Message Board http://www.comptechnews.com/ --
-- CompTechServ Tech Services http://www.comptechserv.com/ --
---------- http://www.comptechnews.com/~reaster/ ------------

Re: Passing tables as parameter

От:
gianpaolo <gianpaolo@preciso.net>
Дата:
On Sunday 07 January 2001 02:23, Robert B. Easter wrote:
> Can I see your function that tried to do it?  Pg 7.1 beta has a new EXECUTE
> statement for PL/pgSQL that allows execution of a query string that can be
> created dynamically (see the development docs at www.postgresql.org).  It
> might be relevant to your problem.

Thanks for your attention
I have this function:
CREATE FUNCTION free_id() RETURNS int4
        as 'SELECT id from pers_id  where flag=0'
        LANGUAGE 'sql';

I have to duplicate it 4 o 5 times, so I thougth to write something like
CREATE FUNCTION free_id(text) RETURNS int4
	as 'SELECT id from $1  where flag=0'
	LANGUAGE 'sql';

to specify different tables when I call the function.
I tried to put different things from '(text)' after the function name, but it 
gives me always an error. I tried also to use the other syntax in select 
(which I saw in the manual is preferred in functions):

CREATE FUNCTION free_id(text) RETURNS int4
	as 'SELECT $1.id where flag=0'
	LANGUAGE 'sql';

but I got nothing good...
any idea? (it's a matter of theory, 'cause I don't care to write down 1 or 4 
functions...)

	have a good day
-- 
gianpaolo racca
gianpaolo@preciso.net
http://www.preciso.net
FAQ