Re:Re: BUG #17036: generated column cann't modifyed auto when update

From: 德哥 <digoal(at)126(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re:Re: BUG #17036: generated column cann't modifyed auto when update
Date: 2021-05-27 02:12:14
Message-ID: 23824c32.12e8.179ab97fa8a.Coremail.digoal@126.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

And immutable function is stable when parameter not change, when parameter changed , the immutable function will recall and recompute.
but in PG 13 and PG 14 , it is also wrong.

```
create or replace function im_now (anyelement) returns timestamptz as $$
select now();
$$ language sql strict immutable;

create table t1 (id int primary key, c1 int, info text, crt_time timestamp,
mod_time timestamp GENERATED ALWAYS AS (im_now(t1)) stored);

insert into t1 (id, c1, info, crt_time) values (1,1,'test', now());

postgres=# select * from t1;
id | c1 | info | crt_time | mod_time
----+----+------+----------------------------+----------------------------
1 | 1 | test | 2021-05-27 10:10:16.190408 | 2021-05-27 10:10:16.190408
(1 row)

postgres=# update t1 set info='a' where id=1;
UPDATE 1
postgres=# select * from t1;
id | c1 | info | crt_time | mod_time
----+----+------+----------------------------+----------------------------
1 | 1 | a | 2021-05-27 10:10:16.190408 | 2021-05-27 10:10:16.190408
(1 row)

postgres=# update t1 set info='abcd' where id=1;
UPDATE 1
postgres=# select * from t1;
id | c1 | info | crt_time | mod_time
----+----+------+----------------------------+----------------------------
1 | 1 | abcd | 2021-05-27 10:10:16.190408 | 2021-05-27 10:10:16.190408
(1 row)

```

--

公益是一辈子的事,I'm Digoal,Just Do It.

在 2021-05-26 20:25:00,"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> 写道:

On Wednesday, May 26, 2021, PG Bug reporting form <noreply(at)postgresql(dot)org> wrote:
The following bug has been logged on the website:

Bug reference: 17036
Logged by: Zhou Digoal
Email address: digoal(at)126(dot)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.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2021-05-27 02:23:01 Re: BUG #17036: generated column cann't modifyed auto when update
Previous Message 德哥 2021-05-27 02:04:32 Re:Re: BUG #17036: generated column cann't modifyed auto when update