Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 3B1529FB2E8 for ; Sun, 1 Apr 2007 15:51:58 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 27806-05 for ; Sun, 1 Apr 2007 15:51:55 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 48F689FB2BE for ; Sun, 1 Apr 2007 15:51:55 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l31IpoD1016017; Sun, 1 Apr 2007 14:51:50 -0400 (EDT) To: Scott Marlowe cc: Daniel CAUNE , pgsql-sql@postgresql.org Subject: Re: Sequence vs Serial In-reply-to: <1175414308.8365.15.camel@localhost.localdomain> References: <000001c77412$6a6e10e0$0b00a8c0@tedy> <1175414308.8365.15.camel@localhost.localdomain> Comments: In-reply-to Scott Marlowe message dated "Sun, 01 Apr 2007 02:58:28 -0500" Date: Sun, 01 Apr 2007 14:51:50 -0400 Message-ID: <16016.1175453510@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/3 X-Sequence-Number: 28003 Scott Marlowe writes: > Daniel CAUNE 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