Re: Sequence vs Serial

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
Cc: Daniel CAUNE <d(dot)caune(at)free(dot)fr>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Sequence vs Serial
Date: 2007-04-01 18:51:50
Message-ID: 16016.1175453510@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Scott Marlowe <smarlowe(at)g2switchworks(dot)com> writes:
> Daniel CAUNE <d(dot)caune(at)free(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Eisentraut 2007-04-02 08:02:26 Calling void functions
Previous Message Scott Marlowe 2007-04-01 07:58:28 Re: Sequence vs Serial