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:45:45 |
Message-ID: | 1c0fae20.18c7.179abb6ab3c.Coremail.digoal@126.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
When i use the im_now(float8 default random()) dynamic parameter, it also not work for PG 14 within generated column.
```
postgres=# drop function im_now(anyelement) ;
DROP FUNCTION
postgres=# drop function im_now ;
DROP FUNCTION
postgres=# drop table t1;
DROP TABLE
postgres=#
postgres=# create or replace function im_now (float8 default random()) returns timestamptz as $$
postgres$# select now();
postgres$# $$ language sql strict immutable;
CREATE FUNCTION
postgres=#
postgres=# create table t1 (id int primary key, c1 int, info text, crt_time timestamp,
postgres(# mod_time timestamp GENERATED ALWAYS AS (im_now()) stored);
CREATE TABLE
postgres=# insert into t1 (id, c1, info, crt_time) values (1,1,'test', now());
INSERT 0 1
postgres=#
postgres=# select * from t1;
id | c1 | info | crt_time | mod_time
----+----+------+----------------------------+----------------------------
1 | 1 | test | 2021-05-27 10:43:32.278616 | 2021-05-27 10:43:32.278616
(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:43:32.278616 | 2021-05-27 10:43:32.278616
(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:43:32.278616 | 2021-05-27 10:43:32.278616
(1 row)
postgres=# select im_now();
im_now
-------------------------------
2021-05-27 10:44:03.749108+08
(1 row)
postgres=# select im_now();
im_now
-------------------------------
2021-05-27 10:44:04.509058+08
(1 row)
postgres=# select im_now();
im_now
-------------------------------
2021-05-27 10:44:06.781393+08
(1 row)
```
--
公益是一辈子的事,I'm Digoal,Just Do It.
在 2021-05-27 10:33:40,"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> 写道:
On Wednesday, May 26, 2021, 德哥 <digoal(at)126(dot)com> wrote:
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);
This seems to be related to this already reported bug (the similar one I noted in my other reply).
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | 德哥 | 2021-05-27 02:47:59 | Re:Re: BUG #17036: generated column cann't modifyed auto when update |
Previous Message | David G. Johnston | 2021-05-27 02:33:40 | Re: BUG #17036: generated column cann't modifyed auto when update |