Re: duplicate sequence, it is possible?

From: Vincent de Phily <vincent(dot)dephily(at)mobile-devices(dot)fr>
To: pgsql-general(at)postgresql(dot)org
Cc: Alban Hertroys <haramrae(at)gmail(dot)com>, Anibal David Acosta <aa(at)devshock(dot)com>
Subject: Re: duplicate sequence, it is possible?
Date: 2011-09-19 10:18:58
Message-ID: 6887261.y4EfI4RQ6g@moltowork
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Monday 19 September 2011 08:19:18 Alban Hertroys wrote:
> On 19 Sep 2011, at 2:57, Anibal David Acosta wrote:
> > Hi everyone.
> >
> > I have a table with a PK, this table has a lot of insert per second (100
> > ~ 150 insert /sec) Sometimes, a get a duplicate key error, but ID is
> > generated from a function (VOLATILE). This function has just one line
> > (select nextval('XXX'))
> >
> > Is possible that this function return same ID for two diff call?
> >
> > Postgres version is 9.0
> >
> > Thanks!
>
> Very unlikely.
> Are you certain that you're not just hitting pre-existing rows that have
> ID's higher than the starting ID of your sequence? Or that there isn't
> another process inserting rows without using the sequence?

Also, why wrap nextval('XXX') instead of using it directly ? Unless your
function does more than "select nextval('XXX')", you're just making your code
harder to read and slightly slower.

--
Vincent de Phily

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tim Uckun 2011-09-19 11:03:32 Getting TOAST errors
Previous Message Koen Van Impe 2011-09-19 10:01:57 Grouping by timestamp, how to return 0 when there's no record