Re: serial column vs. explicit sequence question - Mailing list pgsql-sql

From Tom Lane
Subject Re: serial column vs. explicit sequence question
Date
Msg-id 29716.1024002796@sss.pgh.pa.us
Whole thread Raw
In response to serial column vs. explicit sequence question  (Charlie Toohey <ctoohey@pacbell.net>)
List 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 by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: serial column vs. explicit sequence question
Next
From: Oliver Elphick
Date:
Subject: Re: Another postgres 'file not found' error