Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19 Sep 2010, at 3:43, 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 one row it will be like this
> 
> insert into mytable(mycolumn)values(123)returning id into some_variable;

You can do that for multiple rows just fine, you don't even need plpgsql for that:

development=> \d test
     Table "public.test"
 Column |  Type   | Modifiers 
--------+---------+-----------
 i      | integer | 

development=> INSERT INTO test (i) select x from generate_series(4, 10) t(x) ret
urning i;
 i  
----
  4
  5
  6
  7
  8
  9
 10
(7 rows)

INSERT 0 7


Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.


!DSPAM:737,4c96398f10255076983698!



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux