Re: What is the best practise for "autonumbering"..?

From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Bjorn T Johansen <btj(at)havleik(dot)no>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: What is the best practise for "autonumbering"..?
Date: 2003-05-06 11:47:57
Message-ID: 20030506114757.GB2076@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrass Ziska Davidsen 2003-05-06 12:17:53 Re: restoring ver 7.2 database
Previous Message Alvaro Herrera 2003-05-06 11:41:51 Re: Timebased user access