On Tuesday, December 31, 2024, PG Bug reporting form <
noreply@postgresql.org> wrote:
The following bug has been logged on the website:
Bug reference: 18761
Logged by: Ganeshpandi Eswaran
Email address: ganeshpandi.eswaran@chainsys.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.