Re: how to insert multiple rows and get the ids back in a temp table (pgplsql)?

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Bret Green <bret(dot)green(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to insert multiple rows and get the ids back in a temp table (pgplsql)?
Date: 2010-09-19 14:12:51
Message-ID: 20100919141251.GB24997@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Sep 18, 2010 at 06:43:49PM -0700, Bret Green wrote:
> how can I do the following in plpgsql?
> insert multiple rows in a table
> get the ids (serial) into a temp table (not the client)

for temprec in insert into table (x) select y from z returning id loop
insert into temp teable (q) values (temprec.id);
end loop;

Best regards,

depesz

--
Linkedin: http://www.linkedin.com/in/depesz / blog: http://www.depesz.com/
jid/gtalk: depesz(at)depesz(dot)com / aim:depeszhdl / skype:depesz_hdl / gg:6749007

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2010-09-19 16:25:46 Re: how to insert multiple rows and get the ids back in a temp table (pgplsql)?
Previous Message Francisco Reyes 2010-09-19 12:46:04 Tables with autovacuum_enabled=false still getting vacuumed