Search Postgresql Archives

How to catch the id in a INSERT INTO ... RETURNING function?

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

 



Hi.
I have a table foo(id serial primary key, b int); and I want an insert function

create or replace function insert_to_foo(bvalue integer) returns integer as
declare
   newindex integer;
begin
     ... insert into foo (a,b) values (default,bvalue) returning id
....    <---- THIS LINE
     -- do more with newindex here
     return  newindex;
end;


Well, the problem is that I want the id of the new post to be saved
into the newindex variable for further actions. But how do I catch the
value into the variable?
Should I do:

select id from insert into foo (a,b) values (default,bvalue) returning id;
?

-- 
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