Re: What is the best practise for "autonumbering"..? - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: What is the best practise for "autonumbering"..?
Date
Msg-id 20030506114757.GB2076@dcc.uchile.cl
Whole thread Raw
In response to What is the best practise for "autonumbering"..?  ("Bjorn T Johansen" <btj@havleik.no>)
List pgsql-general
On Tue, May 06, 2003 at 01:09:13PM +0200, Bjorn T Johansen wrote:
> Using Postgres' own serial type or handling the sequences manually?

Use the SERIAL type.  Just create a column with that type and omit it on
INSERT statements -- that way, the default value will be assumed, which
is the next value for the sequence.  You can't have trouble this way.

Note that you can also specify a value for the column in an INSERT (or
UPDATE) statement, and in that case the sequence won't be modified,
which can be a problem later when the sequence hits that value.  You can
also set the column to a number lower than the current value of the
sequence, of course.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
Dios hizo a Adán, pero fue Eva quien lo hizo hombre.


pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Timebased user access
Next
From: Andrass Ziska Davidsen
Date:
Subject: Re: restoring ver 7.2 database