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

From Bret Green
Subject Re: how to insert multiple rows and get the ids back in a temp table (pgplsql)?
Date
Msg-id 830708.47822.qm@web120401.mail.ne1.yahoo.com
Whole thread Raw
In response to Re: how to insert multiple rows and get the ids back in a temp table (pgplsql)?  (hubert depesz lubaczewski <depesz@depesz.com>)
Responses Re: how to insert multiple rows and get the ids back in a temp table (pgplsql)?  (hubert depesz lubaczewski <depesz@depesz.com>)
List pgsql-general
Thanks
Any solution without cursors perhaps?




From: hubert depesz lubaczewski <depesz@depesz.com>
To: Bret Green <bret.green@yahoo.com>
Cc: pgsql-general@postgresql.org
Sent: Sun, September 19, 2010 7:12:51 AM
Subject: Re: [GENERAL] how to insert multiple rows and get the ids back in a temp table (pgplsql)?

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@depesz.com / aim:depeszhdl / skype:depesz_hdl / gg:6749007

pgsql-general by date:

Previous
From: Bret Green
Date:
Subject: Re: how to insert multiple rows and get the ids back in a temp table (pgplsql)?
Next
From: Tatsuo Ishii
Date:
Subject: Re: pgpool-II 3.0 + postgres 9rc1 + md5 authentication not working