| От | Tom Lane |
|---|---|
| Тема | Re: serial column vs. explicit sequence question |
| Дата | |
| Msg-id | 29716.1024002796@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | serial column vs. explicit sequence question (Charlie Toohey <ctoohey@pacbell.net>) |
| Список | pgsql-sql |
Charlie Toohey <ctoohey@pacbell.net> writes:
> A better solution would seem to use a sequence explicitly, rather than a id
> column of type serial. I would obtain the id value from the sequence, and
> then insert this id into the master table and into the detail table.
Yup. But there's no need to change how you create the id column; serial
is just fine, since all it is is a sequence and a DEFAULT nextval('foo').
You just do something like
select nextval('name-of-id-columns-sequence') into $masterid;insert into master(id, ...) values ($masterid, ...);insert
intodetail ... $masterid ...;
rather than letting the default expression do it for you.
regards, tom lane
В списке pgsql-sql по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера