pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Scott Marlowe <smarlowe@g2switchworks.com>
Cc: Daniel CAUNE <d.caune@free.fr>
Cc: pgsql-sql@postgresql.org
Subject: Re: Sequence vs Serial
Date: Sun, 01 Apr 2007 14:51:50 -0400
Message-ID: <16016.1175453510@sss.pgh.pa.us> (raw)
In-Reply-To: <1175414308.8365.15.camel@localhost.localdomain>
References: <000001c77412$6a6e10e0$0b00a8c0@tedy>
	<1175414308.8365.15.camel@localhost.localdomain>

Scott Marlowe <smarlowe@g2switchworks.com> writes:
> Daniel CAUNE <d.caune@free.fr> Said:
>> I was wondering when it is better to choose sequence, and when 
>> it is better to use serial.

> One reason for using serial versus sequence is that a serial gives you
> automatic dependency tracking.

Note that as of 8.2, with the introduction of ALTER SEQUENCE OWNED BY,
you can manipulate the column-to-sequence dependency by hand.  This
means there really is no difference between starting from a separate
sequence and starting with a "serial" column declaration --- you can get
to all the same database states either way.

I tend to think that it's best to use a serial if you intend only the
one column to use the sequence generator, whereas if you intend multiple
columns to be fed from the same sequence generator you ought to declare
the sequence as a freestanding object to start with.  But it's just a
question of style.

			regards, tom lane



view thread (3+ messages)

Message-ID: <16016.1175453510@sss.pgh.pa.us>
Permalink:  ../16016.1175453510@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16016.1175453510@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, smarlowe@g2switchworks.com, d.caune@free.fr
  Subject: Re: Sequence vs Serial
  In-Reply-To: <16016.1175453510@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