Re: serial column vs. explicit sequence question

Поиск
Список
Период
Сортировка
От 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 по дате отправления:

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: serial column vs. explicit sequence question
Следующее
От: Oliver Elphick
Дата:
Сообщение: Re: Another postgres 'file not found' error