"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