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

Поиск
Список
Период
Сортировка
От A B
Тема How to catch the id in a INSERT INTO ... RETURNING function?
Дата
Msg-id dbbf25900902010237l512eaeb2g4c8dcf52240d968f@mail.gmail.com
обсуждение исходный текст
Ответы Resp.: How to catch the id in a INSERT INTO ... RETURNING function?  (Osvaldo Kussama <osvaldo.kussama@gmail.com>)
Re: How to catch the id in a INSERT INTO ... RETURNING function?  (Gerhard Heift <ml-postgresql-20081012-3518@gheift.de>)
Список pgsql-general
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;
?

В списке pgsql-general по дате отправления:

Предыдущее
От: "Preethi Valsalan"
Дата:
Сообщение: urgent request : PSQLException: FATAL: could not open relation XXX: No such file or directory
Следующее
От: Scott Marlowe
Дата:
Сообщение: Re: ALTER TABLE with TYPE serial does not work