X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 48758D1B1CF for ; Sat, 19 Jun 2004 15:39:14 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05958-01 for ; Sat, 19 Jun 2004 18:39:11 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id DCD4FD1B173 for ; Sat, 19 Jun 2004 15:39:09 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i5JId8o8017841; Sat, 19 Jun 2004 14:39:08 -0400 (EDT) To: "Riccardo G. Facchini" Cc: Phil Endecott , pgsql-sql@postgresql.org Subject: Re: plpgsql - Insert from a record variable? In-reply-to: <20040619060330.83941.qmail@web13901.mail.yahoo.com> References: <20040619060330.83941.qmail@web13901.mail.yahoo.com> Comments: In-reply-to "Riccardo G. Facchini" message dated "Fri, 18 Jun 2004 23:03:30 -0700" Date: Sat, 19 Jun 2004 14:39:08 -0400 Message-ID: <17840.1087670348@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/165 X-Sequence-Number: 18110 "Riccardo G. Facchini" 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