Re: plpgsql - Insert from a record variable? - Mailing list pgsql-sql

From Phil Endecott
Subject Re: plpgsql - Insert from a record variable?
Date
Msg-id 4357626@chezphil.org
Whole thread Raw
In response to Re: plpgsql - Insert from a record variable?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: plpgsql - Insert from a record variable?
Re: plpgsql - Insert from a record variable?
List pgsql-sql
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
thiswith inheritance; the function looks up a row in a base table, finds the derived table in which it really exists
usingpg_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
introspectionmechanism so that I can loop over each element of the record and construct the insert as a string.  Maybe
thisis possible using a different server-side language?  I've just had an idea: perhaps rather than inspecting the
recordvariable to see what fields it contains, I can look at the table to see what columns it contains (since this
amountsto the same thing).  Presumably I can do this using information_schema.columns.  I'll have a go.
 

--Phil.


pgsql-sql by date:

Previous
From: "Jie Liang"
Date:
Subject: Re: [JDBC] Prepare Statement
Next
From: "Phil Endecott"
Date:
Subject: Re: plpgsql - Insert from a record variable?