From: 德哥 <digoal@126.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re:Re: BUG #17036: generated column cann't modifyed auto when update
Date: Thu, 27 May 2021 10:04:32 +0800 (CST)
Message-ID: <68e07f0f.1179.179ab90ee08.Coremail.digoal@126.com> (raw)
In-Reply-To: <CAKFQuwarr8b2=2j2J4GuSV-FwqAXq38ebFR_wTUY=Lg9_YLCJg@mail.gmail.com>
References: <17036-e4d41f4221873a17@postgresql.org>
<CAKFQuwarr8b2=2j2J4GuSV-FwqAXq38ebFR_wTUY=Lg9_YLCJg@mail.gmail.com>
But in PostgreSQL 12, it works fine.
```
postgres=> create or replace function im_now () returns timestamptz as $$
postgres$> select now();
postgres$> $$ language sql strict immutable;
CREATE FUNCTION
postgres=>
postgres=> create table t1 (id int primary key, info text, crt_time timestamp,
postgres(> mod_time timestamp GENERATED ALWAYS AS (im_now()) stored);
CREATE TABLE
postgres=>
postgres=> insert into t1 (id, info, crt_time) values (1,'test', now());
INSERT 0 1
postgres=>
postgres=> select * from t1;
id | info | crt_time | mod_time
----+------+----------------------------+----------------------------
1 | test | 2021-05-27 10:01:58.361174 | 2021-05-27 10:01:58.361174
(1 row)
postgres=>
postgres=> update t1 set info='a' where id=1;
UPDATE 1
postgres=> select * from t1;
id | info | crt_time | mod_time
----+------+----------------------------+----------------------------
1 | a | 2021-05-27 10:01:58.361174 | 2021-05-27 10:01:58.896861
(1 row)
postgres=> create or replace function im_now () returns timestamptz as $$
postgres$> select CURRENT_TIMESTAMP;
postgres$> $$ language sql strict immutable;
CREATE FUNCTION
postgres=> update t1 set info='a' where id=1;
UPDATE 1
postgres=> select * from t1; id | info | crt_time | mod_time
----+------+----------------------------+----------------------------
1 | a | 2021-05-27 10:01:58.361174 | 2021-05-27 10:02:24.134303
(1 row)
postgres=> update t1 set info='a' where id=1;
UPDATE 1
postgres=> select * from t1;
id | info | crt_time | mod_time
----+------+----------------------------+----------------------------
1 | a | 2021-05-27 10:01:58.361174 | 2021-05-27 10:02:34.164966
(1 row)
postgres=> update t1 set info='a' where id=1;
UPDATE 1
postgres=> select * from t1;
id | info | crt_time | mod_time
----+------+----------------------------+----------------------------
1 | a | 2021-05-27 10:01:58.361174 | 2021-05-27 10:02:37.535282
(1 row)
postgres=> create or replace function im_now () returns timestamptz as $$ select now(); $$ language sql strict immutable;
CREATE FUNCTION
postgres=> update t1 set info='a' where id=1; UPDATE 1
postgres=> select * from t1; id | info | crt_time | mod_time
----+------+----------------------------+----------------------------
1 | a | 2021-05-27 10:01:58.361174 | 2021-05-27 10:03:02.665515
(1 row)
postgres=> update t1 set info='a' where id=1;
UPDATE 1
postgres=> select * from t1;
id | info | crt_time | mod_time
----+------+----------------------------+----------------------------
1 | a | 2021-05-27 10:01:58.361174 | 2021-05-27 10:03:05.414793
(1 row)
```
--
公益是一辈子的事,I'm Digoal,Just Do It.
在 2021-05-26 20:25:00,"David G. Johnston" <david.g.johnston@gmail.com> 写道:
On Wednesday, May 26, 2021, PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:
Bug reference: 17036
Logged by: Zhou Digoal
Email address: digoal@126.com
PostgreSQL version: 14beta1
Operating system: CentOS 7.7 x64
Description:
postgres=> create or replace function im_now () returns timestamptz as $$
select CURRENT_TIMESTAMP;
$$ language sql strict immutable;
CREATE FUNCTION
why mod_time cann't updated automatic?
Because that isn’t how this thing works...the lie you told it about being immutable is a dead giveaway,
David J.
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: digoal@126.com, david.g.johnston@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re:Re: BUG #17036: generated column cann't modifyed auto when update
In-Reply-To: <68e07f0f.1179.179ab90ee08.Coremail.digoal@126.com>
* 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