Re: plpgsql - Insert from a record variable?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: plpgsql - Insert from a record variable?
Дата
Msg-id 17840.1087670348@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: plpgsql - Insert from a record variable?  ("Riccardo G. Facchini" <abief_ag_-postgresql@yahoo.com>)
Ответы Re: plpgsql - Insert from a record variable?
Список pgsql-sql
"Riccardo G. Facchini" <abief_ag_-postgresql@yahoo.com> writes:
> --- Phil Endecott <__> wrote:
>> I'm writing a simple plpgsql function that selects a row from a
>> table, modifies it slightly, and inserts the modified version.  This
>> sounds simple, but I can't find how to do the insert in a simple
>> generic fashion: although SELECT has a form that puts the result in a
>> record variable, INSERT doesn't seem to have anything similar.

> I'm not sure if it will work, but have you tried [snip]

> declare r record;
>   insert into table select r.*;

I don't know of any way to handle this in existing releases ---
plpgsql's support for rowtype variables is just too limited.
However, in 7.5 you will be able to do either of
insert into table select r.*;insert into table values(r.*);

so long as r is declared to be of a named rowtype (not just RECORD;
that doesn't have a known field list to plan the query with).  For
instance I was just experimenting with this test case:

create or replace function fooey(int) returns void as '
declare r foo;
begin select * into r from foo where id = $1; r.f1 = ''baz''; insert into foo select r.*; return;
end' language plpgsql;
        regards, tom lane


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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: In 7.4 ensure you have DEFAULT now () with no spaces
Следующее
От: Tom Lane
Дата:
Сообщение: Re: In 7.4 ensure you have DEFAULT now () with no spaces