Re: [INTERFACES] ecpg and getting just assigned serial number
В списке pgsql-interfaces по дате отправления:
| От | Tom Lane |
|---|---|
| Тема | Re: [INTERFACES] ecpg and getting just assigned serial number |
| Дата | |
| Msg-id | 2567.937152101@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | ecpg and getting just assigned serial number (theofilu@eunet.at (Theofilu Andreas)) |
| Список | pgsql-interfaces |
theofilu@eunet.at (Theofilu Andreas) writes:
> to Informix's 'esqlc'. However. I have a table with a field of type
> 'serial'. Now I've no problem to insert any sentences into this table, but
> immediately after inserting a new sentence I need the newly assigned number
> to the serial field in the table. How can I access this number?
Postgres doesn't return that number automatically; you'll have to run a
separate query to find out what was inserted. You could do something
likeselect serialcolumn from table where oid = NNNN;
since a single-row insert does return the OID of the inserted row.
(Note this will be pretty slow if the table is big and does not have
an index on OID.)
Another possibility is to execute nextval() for yourself and then insert
that result explicitly when you create the row. Still takes two queries,
though.
regards, tom lane
В списке pgsql-interfaces по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера