Unexpected behavior of updating domain array that is based on a composite

From: Japin Li <japinli(at)hotmail(dot)com>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Unexpected behavior of updating domain array that is based on a composite
Date: 2021-10-19 16:34:18
Message-ID: MEYP282MB1669BED5CEFE711E00C7421EB6BD9@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi, hackers

While reading the patch in [1], I found there is an unexpected behavior when
update the domain array that is based on a composite.

Steps to reproduce:

1)
CREATE TYPE two_ints as (if1 int, if2 int);
CREATE DOMAIN domain AS two_ints CHECK ((VALUE).if1 > 0);
CREATE TABLE domain_indirection_test (f1 int, f3 domain, domain_array domain[]);
INSERT INTO domain_indirection_test (f1,f3.if1) VALUES (0, 1);

2) The following test besed on patch in [1].
UPDATE domain_indirection_test SET domain_array[0].if2 = 5;
select * from domain_indirection_test;
f1 | f3 | domain_array
----+------+----------------
0 | (1,) | [0:0]={"(,5)"}

3)
UPDATE domain_indirection_test SET domain_array[0].if1 = 10;
select * from domain_indirection_test ;
f1 | f3 | domain_array
----+------+-----------------
0 | (1,) | [0:0]={"(10,)"}
(1 row)

4)
UPDATE domain_indirection_test SET domain_array[0].if1 = 10, domain_array[0].if2 = 5;
select * from domain_indirection_test ;
f1 | f3 | domain_array
----+------+----------------
0 | (1,) | [0:0]={"(,5)"}
(1 row)

5)
UPDATE domain_indirection_test SET domain_array[0].if2 = 10, domain_array[0].if1 = 5;
select * from domain_indirection_test ;
f1 | f3 | domain_array
----+------+----------------
0 | (1,) | [0:0]={"(5,)"}
(1 row)

6) Work as expected.
UPDATE domain_indirection_test SET domain_array[0] = (10, 5);
select * from domain_indirection_test ;
f1 | f3 | domain_array
----+------+------------------
0 | (1,) | [0:0]={"(10,5)"}
(1 row)

[1] https://www.postgresql.org/message-id/PH0PR21MB132823A46AA36F0685B7A29AD8BD9%40PH0PR21MB1328.namprd21.prod.outlook.com
--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2021-10-19 16:35:39 Re: XTS cipher mode for cluster file encryption
Previous Message Robert Haas 2021-10-19 16:12:00 Re: parallelizing the archiver