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 592BFD1B1A1 for ; Fri, 11 Jun 2004 11:42:17 -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 53414-03 for ; Fri, 11 Jun 2004 14:42:13 +0000 (GMT) Received: from mail231.csoft.net (resin.csoft.net [63.111.22.86]) by svr1.postgresql.org (Postfix) with SMTP id 4B647D1B169 for ; Fri, 11 Jun 2004 11:42:07 -0300 (ADT) Received: (qmail 32018 invoked from network); 11 Jun 2004 14:42:09 -0000 Received: from unknown (HELO chezphil.org) (63.111.27.87) by mail231.csoft.net with SMTP; 11 Jun 2004 14:42:09 -0000 Content-Disposition: inline Content-Transfer-Encoding: binary Content-Type: text/plain MIME-Version: 1.0 X-Mailer: MIME::Lite 3.01 (F2.71; A1.17; B2.12; Q2.03) From: "Phil Endecott" To: pgsql-sql@postgresql.org Subject: plpgsql - Insert from a record variable? Date: Fri, 11 Jun 2004 10:42:09 -0400 X-Mailer: Phil's WebMail Message-Id: <4899937@chezphil.org> 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/100 X-Sequence-Number: 18045 Dear Postgresql experts, 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. What I'd like to be able to write is something like this: DECLARE R RECORD; BEGIN SELECT * INTO R FROM TABLE WHERE id=n; R.something := x; INSERT INTO TABLE R; END But as far as I can see the only syntax that is allowed for INSERT is the normal INSERT INTO TABLE (x,y,z) VALUES (a,b,c). To achieve what I want to do I'd need to iterate over the fields of the record (how?) and build up the string of the INSERT query. It seems odd that SELECT can use a record variable but INSERT can't, so I wonder if I have missed something. Any suggestions? Thanks in advance for any help anyone can offer. Regards, --Phil.