Re: BUG #5027: SQL query error?

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Dmitry <master(at)hsdesign(dot)ru>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5027: SQL query error?
Date: 2009-09-02 13:29:27
Message-ID: 603c8f070909020629h3b17f911hea11fd155a2c4eb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Sep 1, 2009 at 9:51 AM, Dmitry<master(at)hsdesign(dot)ru> wrote:
>
> The following bug has been logged online:
>
> Bug reference:      5027
> Logged by:          Dmitry
> Email address:      master(at)hsdesign(dot)ru
> PostgreSQL version: 8.3.5
> Operating system:   ALT Linux
> Description:        SQL query error?
> Details:
>
> Hello,
>
> I try to make user rating by this query:
>
> "BEGIN;
> ALTER SEQUENCE service.rate_seq RESTART 1;
> UPDATE service.user u
>   SET rate = sr.rate
> FROM (
>   SELECT user_id, nextval('service.rate_seq') as rate
>   FROM
>     (
>      SELECT user_id, score FROM service.user
>      ORDER BY score DESC
>     ) a
>   ) sr
> WHERE u.user_id = sr.user_id;
> END;"
>
> all work fine, but if while this query is executing another process do
> "UPDATE service.user SET score=score+1" i get wrong sequence value; for
> example
> if user count = 55000 i can get 512321 in sequence ;(
> why? query error?

Because sequences are non-transactional. See the description of
nextval(), here:

http://www.postgresql.org/docs/current/interactive/functions-sequence.html

...Robert

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Magnus Hagander 2009-09-02 13:39:07 Re: BUG #5019: Nao funciona
Previous Message Heikki Linnakangas 2009-09-02 11:00:14 Re: BUG #5025: Aggregate function with subquery in 8.3 and 8.4.