Re: libpq - getting value of SERIAL field when INSERT-ing?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: libpq - getting value of SERIAL field when INSERT-ing?
Дата
Msg-id 620.1314749568@sss.pgh.pa.us
обсуждение исходный текст
Ответ на libpq - getting value of SERIAL field when INSERT-ing?  (Roy's Email <rmw256@hotmail.com>)
Список pgsql-novice
"Roy's Email" <rmw256@hotmail.com> writes:
> Using libpq, how do I get the return value from an INSERT statement?

> CREATE TABLE foo ( pk SERIAL , val text, PRIMARY KEY (pk) );
> INSERT INTO foo VALUES ( DEFAULT, 'stuff' ) RETURNING (pk);

> How do I get the value assigned to 'pk'?  I assume it's in the 'PGresult' returned from 'PQexec()', but I can't find
anythingin the documentation for 'PGresult' that appears to discuss this particular use. 

The PGresult is exactly the same as if you'd done "SELECT pk FROM ..."

            regards, tom lane

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

Предыдущее
От: Roy's Email
Дата:
Сообщение: libpq - getting value of SERIAL field when INSERT-ing?
Следующее
От: 金 今花
Дата:
Сообщение: pg_dump error