Re: Variable column name in plpgsql function

Поиск
Список
Период
Сортировка
От mark
Тема Re: Variable column name in plpgsql function
Дата
Msg-id 41AE0385.5040505@markreid.org
обсуждение исходный текст
Ответ на Re: Variable column name in plpgsql function  (Richard Huxton <dev@archonet.com>)
Список pgsql-general
Richard Huxton wrote:

> George Woodring wrote:
>
>>
>> Is possible to declare a variable to build the column name
>>
>> Tableid varchar(20) := TG_RELNAME || ''id'';
>>
>> And then use this variable to get the PK value?
>>
>> Tableidvalue int4 := NEW.tableid;
>
>
> No. You can build a dynamic query via EXECUTE, but that can't access
> NEW/OLD.
>
If there's only the two possibilities, you could just use something like
IF TG_RELNAME = 'table1' THEN
    id := NEW.table1id;
ELSE
    id := NEW.table2id;
END IF;

But dynamically referring to NEW.variable doesn't work in plpgsql.
Apparently you can do this in some of the other pl languages though
(plperl for example).

-Mark.



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

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Variable column name in plpgsql function
Следующее
От: "Sally Sally"
Дата:
Сообщение: autocommit and transactions