- milestone: 2663467 --> Development Queue
A query like :
WITH rcte AS ( SELECT sum(id) AS totalid FROM tab1 )
postgres-# UPDATE tab1 SET id = id + totalid FROM rcte
has some existing issue due to which it gives:
-ERROR: input of anonymous composite types is not implemented
But after trigger implementation, it would not error out, but in some cases it give wrong results like the e.g. shown below.
postgres=# \set REP 'distribute by hash(val) '
postgres=# CREATE TABLE tab1 ( id int, val text ) :REP ;
CREATE TABLE
postgres=# INSERT INTO tab1 VALUES ( 1, 'p1' );
INSERT 0 1
postgres=# INSERT INTO tab1 VALUES ( 11, 'c11' ),( 12, 'c12' );
INSERT 0 2
postgres=# INSERT INTO tab1 VALUES ( 23, 'c21' ),( 24, 'c22' );
INSERT 0 2
postgres=# WITH rcte AS ( SELECT sum(id) AS totalid FROM tab1 )
postgres-# UPDATE tab1 SET id = id + totalid FROM rcte;
UPDATE 5
postgres=# SELECT * FROM tab1 ORDER BY id;
id | val
----+-----
72 | p1
82 | c11
83 | c12
94 | c21
95 | c22
(5 rows)
postgres=# WITH wcte AS ( INSERT INTO tab1 VALUES ( 42, 'new' ) RETURNING id AS newid )
postgres-# UPDATE tab1 SET id = id + newid FROM wcte;
UPDATE 6
postgres=# SELECT * FROM tab1 ORDER BY id;
id | val
-----+-----
84 | new <---- This PG shows: 48 | new, not 84 | new.
114 | p1
124 | c11
125 | c12
136 | c21
137 | c22
(6 rows)
Above, the UPDATE also updates the latest inserted value 42 and sets its value to 42+newid = 84. While in PG, it does not update the inserted value.
After the trigger work, I am keeping this incorrect output in with_1.out. Currently there is no with_1.out; with_1.out itself had incorrect results.