Passing the table name as a function argument in PLPGSQL

Поиск
Список
Период
Сортировка
От Vincent Ficet
Тема Passing the table name as a function argument in PLPGSQL
Дата
Msg-id 4DF70D30.90303@bull.net
обсуждение исходный текст
Ответы Re: Passing the table name as a function argument in PLPGSQL  (Andreas Kretschmer <akretschmer@spamfence.net>)
Список pgsql-novice
Hello,


Is it possible to pass the name of the table to update to a given function ?

For example, how can I do something like:

CREATE FUNCTION compute_ipaddr(CHARACTER VARYING, INET)
    AS $_$
DECLARE
   tbl_name ALIAS FOR $1;
   module_ipaddr ALIAS FOR $2;
BEGIN
 UPDATE tbl_name SET ipaddr = module_ipaddr  ....

END;
$_$
    LANGUAGE PLPGSQL;


Since this does not work, I have to do

IF tbl_name = 'controller' THEN
  UPDATE controller SET ipaddr = module_ipaddr ...
ELSE IF tbl_name = 'server' THEN
  UPDATE server SET ipaddr = module_ipaddr ...
[ ...]


Is there a technique to pass the table name and so make the code more
generic ?

Thanks for your help

Vincent






В списке pgsql-novice по дате отправления:

Предыдущее
От: "Jean-Yves F. Barbier"
Дата:
Сообщение: Re: permissions PB [SOLVED]
Следующее
От: Maalini Samuganardan
Дата:
Сообщение: Scheduling autovacuum