Re: BUG #18761: Sequence Value Discrepancy After Running VACUUM ANALYZE

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "ganeshpandi(dot)eswaran(at)chainsys(dot)com" <ganeshpandi(dot)eswaran(at)chainsys(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #18761: Sequence Value Discrepancy After Running VACUUM ANALYZE
Date: 2024-12-31 13:42:59
Message-ID: CAKFQuwaHiXeyuWF=sqk1q+71qA3TWWPf01qvL2Li=mX0_atwOQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tuesday, December 31, 2024, PG Bug reporting form <noreply(at)postgresql(dot)org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference: 18761
> Logged by: Ganeshpandi Eswaran
> Email address: ganeshpandi(dot)eswaran(at)chainsys(dot)com
> PostgreSQL version: 13.15
> Operating system: Oracle sql developer
> Description:
>
> Issue Report: Sequence Value Discrepancy After Running VACUUM ANALYZE
> Description:
> After executing the following UPDATE query, which updates a table using a
> PostgreSQL sequence to assign a batch number:
>
> SQL query:
>
> UPDATE stgtbl_837465r4 STGTBL
> SET ATTR_7 = PVQUERY.batch_number, ATTR_1 = PVQUERY.batch_number , TF_1 =
> 'S'
> FROM (
> SELECT CAST(BATCH_SEQ AS NUMERIC) AS BATCH_NUMBER,
> CAST(BATCH_SEQ AS VARCHAR(50)) AS BATCH,
> BATCH_TEXT
> FROM (
> SELECT NEXTVAL('sample_sequence__2899') AS BATCH_SEQ,
> 'A' AS BATCH_TEXT
> FROM test_act
> ) A
> ) PVQUERY
> WHERE PVQUERY.batch_text IS NOT NULL;
>

You never equate the rows of PVQUERY to the rows of stgtbl_837465r4.
Tables are not ordered so unless you write what is basically a join
condition if the where clause an update-from query is malformed and you end
up with non-sensical random changes (well, unless the from query only
produces a single row).

David J.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2024-12-31 15:24:16 Re: BUG #18761: Sequence Value Discrepancy After Running VACUUM ANALYZE
Previous Message PG Bug reporting form 2024-12-31 09:26:36 BUG #18761: Sequence Value Discrepancy After Running VACUUM ANALYZE