Re: Looking for help regarding getting the latest inserted sequence value.
В списке pgsql-general по дате отправления:
| От | Richard Broersma Jr |
|---|---|
| Тема | Re: Looking for help regarding getting the latest inserted sequence value. |
| Дата | |
| Msg-id | 269699.61302.qm@web31814.mail.mud.yahoo.com обсуждение исходный текст |
| Ответ на | Re: Looking for help regarding getting the latest inserted sequence value. (Magnus Hagander <magnus@hagander.net>) |
| Ответы |
Re: Looking for help regarding getting the latest inserted sequence value.
|
| Список | pgsql-general |
--- Magnus Hagander <magnus@hagander.net> wrote:
> If you're on 8.2 the easiest way is to use INSERT RETURNING. For example:
> INSERT INTO t (somefield) VALUES ('somevalue') RETURNING pkey
>
> with pkey being the SERIAL field.
I don't want to derail the thread too much, but would it be nice if the returning could be used in
a insert sub-query?
INSERT INTO Childtable ( parentfkey, childname )
VALUES ( ( INSERT INTO Parenttable ( parentname )
VALUES ( 'FRED' ) RETURNING pkey ), 'Jed');
This with one statement, you could insert into two or more tables.
Regards,
Richard Broersma Jr.
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера