From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: hisahiro@freemind.co.jp
Subject: BUG #17823: Generated columns not always updated correctly
Date: Mon, 06 Mar 2023 07:26:42 +0000
Message-ID: <17823-b64909cf7d63de84@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 17823
Logged by: Hisahiro Kauchi
Email address: hisahiro@freemind.co.jp
PostgreSQL version: 15.2
Operating system: CentOS 7
Description:
I found that the generated columns are sometimes not updated.
1. Create a table with a generated column, and insert a row:
test=# create table test(id serial primary key, a int, b int generated
always as (a + 1) stored);
CREATE TABLE
test=# insert into test(a) values (1);
INSERT 0 1
test=# select * from test;
id | a | b
----+---+---
1 | 1 | 2
(1 row)
2. Start Transaction A and update the row:
==== Transaction A ====
test=# begin;
BEGIN
test=*# update test set a=2 where id=1;
UPDATE 1
test=*# select * from test;
id | a | b
----+---+---
1 | 2 | 3
(1 row)
3. Before committing transaction A, start Transaction B to update the same
row:
==== Transaction B ====
test=# begin;
BEGIN
test=*# update test set a=3 where id=1;
(Waiting for Transaction A to commit)
4. Commit Transaction A:
==== Transaction A ====
test=*# end;
COMMIT
5. The UPDATE of Transaction B is executed:
==== Transaction B ====
UPDATE 1
test=*# end;
COMMIT
6. Check the result:
test=*# select * from test;
id | a | b
----+---+---
1 | 3 | 3
(1 row)
The generated column "b" should be updated correctly to reflect the new
value of "a" (i.e., b=4).
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, hisahiro@freemind.co.jp
Subject: Re: BUG #17823: Generated columns not always updated correctly
In-Reply-To: <17823-b64909cf7d63de84@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox