Re: Need a script that bakes INSERT script from SELECT results

From: John DeSoi <desoi(at)pgedit(dot)com>
To: ShuA <noface(at)inbox(dot)ru>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Need a script that bakes INSERT script from SELECT results
Date: 2009-04-16 12:25:15
Message-ID: 5CDAA3CE-6B0F-4177-A5E1-241584EB6A90@pgedit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Apr 16, 2009, at 7:29 AM, ShuA wrote:

> Could someone post an example how to LOOP through row fields to wrap
> them into 'VALUES(...,,)' list?

If you declare record or table row types, you can insert the values
using (rec.*), something like this:

create or replace function test ()
returns void as $$
declare
rec record;
begin
for rec in select * from whatever loop
insert into some_table values (rec.*);
end loop;
end;
$$ language plpgsql;

John DeSoi, Ph.D.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message ShuA 2009-04-16 13:24:05 Re[2]: Need a script that bakes INSERT script from SELECT results
Previous Message ShuA 2009-04-16 11:29:38 Need a script that bakes INSERT script from SELECT results