pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Charlie Toohey <ctoohey@pacbell.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: serial column vs. explicit sequence question
Date: Thu, 13 Jun 2002 17:13:16 -0400
Message-ID: <29716.1024002796@sss.pgh.pa.us> (raw)
In-Reply-To: <20020613200344.1B97A476B74@postgresql.org>
References: <20020613200344.1B97A476B74@postgresql.org>

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 into detail ... $masterid ...;

rather than letting the default expression do it for you.

			regards, tom lane



view thread (8+ messages)  latest in thread

Message-ID: <29716.1024002796@sss.pgh.pa.us>
Permalink:  ../29716.1024002796@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/29716.1024002796@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ctoohey@pacbell.net
  Subject: Re: serial column vs. explicit sequence question
  In-Reply-To: <29716.1024002796@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox