Re: Equivalent for AUTOINCREMENT? - Mailing list pgsql-general

From Bruce Momjian
Subject Re: Equivalent for AUTOINCREMENT?
Date
Msg-id 200811061855.mA6Ite916848@momjian.us
Whole thread Raw
In response to Re: Equivalent for AUTOINCREMENT?  (Michelle Konzack <linux4michelle@tamay-dogan.net>)
List pgsql-general
Michelle Konzack wrote:
-- Start of PGP signed section.
> Hello Michael,
>
> Am 2008-10-31 11:15:54, schrieb Michael Hall:
> > > I have a table where I have a serialnumber which shuld be  increased  be
> > > each INSERT.  I know I can use max() to get the highest number, but  how
> > > can I use it in a INSERT statement?
> >
> > Have a look in the manual for the SERIAL data type.
> > For fields with a SERIAL data type, you can use DEFAULT in an INSERT statement.
>
> OK, the SERIAL is now working, but there is ONE problem.
>
> If the INSERT fails, the SERIAL is in any case increased...
>
> So this was the reason, why I have tried to use max(serno)  and  add  +1
> the get the next value for "serno".
>
> Is there a solution for it?

You should read our three FAQ entries about sequences:

    http://www.postgresql.org/docs/faqs.FAQ.html#item4.11.1

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

pgsql-general by date:

Previous
From: Martin Gainty
Date:
Subject: Re: Ayuda
Next
From: "Scott Marlowe"
Date:
Subject: Re: Equivalent for AUTOINCREMENT?