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 2C421D1B193 for ; Mon, 21 Jun 2004 14:23:43 -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 22710-03 for ; Mon, 21 Jun 2004 17:23:41 +0000 (GMT) Received: from mail231.csoft.net (resin.csoft.net [63.111.22.86]) by svr1.postgresql.org (Postfix) with SMTP id 4C9BCD1B18E for ; Mon, 21 Jun 2004 14:23:38 -0300 (ADT) Received: (qmail 22238 invoked from network); 21 Jun 2004 17:23:33 -0000 Received: from unknown (HELO chezphil.org) (63.111.27.87) by mail231.csoft.net with SMTP; 21 Jun 2004 17:23:33 -0000 Content-Disposition: inline Content-Transfer-Encoding: binary Content-Type: text/plain MIME-Version: 1.0 X-Mailer: MIME::Lite 3.01 (F2.72; A1.17; B2.21; Q2.21) From: "Phil Endecott" To: Tom Lane , "Riccardo G. Facchini" , Phil Endecott , pgsql-sql@postgresql.org Subject: Re: plpgsql - Insert from a record variable? Date: Mon, 21 Jun 2004 13:23:33 -0400 X-Mailer: Phil's WebMail Message-Id: <4357626@chezphil.org> In-Reply-To: <17840.1087670348@sss.pgh.pa.us> References: <20040619060330.83941.qmail@web13901.mail.yahoo.com> <17840.1087670348@sss.pgh.pa.us> 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/198 X-Sequence-Number: 18143 Phil> Insert from a record variable? Riccardo> Try insert into table select r.*; Tom> in 7.5 Tom> insert into table select r.*; Tom> insert into table values(r.*); Tom> so long as r is declared to be of a named rowtype (not just Tom> RECORD) Thanks! Unfortunately I need record, rather than %rowtype. See my later email where I describe how I am trying to use this with inheritance; the function looks up a row in a base table, finds the derived table in which it really exists using pg_class.relname, and then inserts a modified copy of the row in the derived table. I'm not concerned about the performance issues to do with pre-planning the queries. I think what I really need is an introspection mechanism so that I can loop over each element of the record and construct the insert as a string. Maybe this is possible using a different server-side language? I've just had an idea: perhaps rather than inspecting the record variable to see what fields it contains, I can look at the table to see what columns it contains (since this amounts to the same thing). Presumably I can do this using information_schema.columns. I'll have a go. --Phil.