BUG #18761: Sequence Value Discrepancy After Running VACUUM ANALYZE

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: ganeshpandi(dot)eswaran(at)chainsys(dot)com
Subject: BUG #18761: Sequence Value Discrepancy After Running VACUUM ANALYZE
Date: 2024-12-31 09:26:36
Message-ID: 18761-624bbdc5e7434bdb@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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;

Expected Behavior:
The sequence (sample_sequence__2899) should return different sequence
numbers (e.g., 1, 2, 3) for each record updated in the UPDATE query.

Observed Behavior:
After running VACUUM ANALYZE on the table stgtbl_837465r4, the sequence
returns the same value (e.g., 4) for all records, even though it should
return unique values for each record.

Steps to Reproduce:
Run the UPDATE query as stated above.
Observe the sequence values returned for each record before VACUUM ANALYZE
is executed.
Run the VACUUM ANALYZE operation on the table stgtbl_837465r4.
Re-run the same UPDATE query.
Observe that the sequence returns the same value (e.g., 4) for all updated
records.

Kindly provide a solution to the issue due to this issue affecting our most
functionality

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2024-12-31 13:42:59 Re: BUG #18761: Sequence Value Discrepancy After Running VACUUM ANALYZE
Previous Message PG Bug reporting form 2024-12-31 09:01:30 BUG #18760: ../doc/src/sgml/postgres.sgml:24: element book: validity error : No declaration for attribute id of