Skip to content

Commit 9bc933b

Browse files
committed
Fix 8.2 breakage of domains over array types, and add a regression test case
to cover it. Per report from Anton Pikhteryev.
1 parent 79929ff commit 9bc933b

File tree

3 files changed

+55
-19
lines changed

3 files changed

+55
-19
lines changed

src/backend/utils/cache/lsyscache.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.149 2007/03/17 00:11:05 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.150 2007/03/19 16:30:31 tgl Exp $
1111
*
1212
* NOTES
1313
* Eventually, the index information should go through here, too.
@@ -1767,10 +1767,10 @@ getTypeIOParam(HeapTuple typeTuple)
17671767

17681768
/*
17691769
* Array types get their typelem as parameter; everybody else gets their
1770-
* own type OID as parameter. (This is a change from 8.0, in which only
1771-
* composite types got their own OID as parameter.)
1770+
* own type OID as parameter. (As of 8.2, domains must get their own OID
1771+
* even if their base type is an array.)
17721772
*/
1773-
if (OidIsValid(typeStruct->typelem))
1773+
if (typeStruct->typtype == 'b' && OidIsValid(typeStruct->typelem))
17741774
return typeStruct->typelem;
17751775
else
17761776
return HeapTupleGetOid(typeTuple);

src/test/regress/expected/domain.out

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ NOTICE: drop cascades to type dependenttypetest
1515
-- this should fail because already gone
1616
drop domain domaindroptest cascade;
1717
ERROR: type "domaindroptest" does not exist
18-
-- TEST Domains.
18+
-- Test domain input.
19+
-- Note: the point of checking both INSERT and COPY FROM is that INSERT
20+
-- exercises CoerceToDomain while COPY exercises domain_in.
1921
create domain domainvarchar varchar(5);
2022
create domain domainnumeric numeric(8,2);
2123
create domain domainint4 int4;
@@ -72,20 +74,22 @@ drop domain domainvarchar restrict;
7274
drop domain domainnumeric restrict;
7375
drop domain domainint4 restrict;
7476
drop domain domaintext;
75-
-- Array Test
77+
-- Test domains over array types
7678
create domain domainint4arr int4[1];
77-
create domain domaintextarr text[2][3];
79+
create domain domainchar4arr varchar(4)[2][3];
7880
create table domarrtest
7981
( testint4arr domainint4arr
80-
, testtextarr domaintextarr
82+
, testchar4arr domainchar4arr
8183
);
8284
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"}}');
8385
INSERT INTO domarrtest values ('{{2,2},{2,2}}', '{{"a","b"}}');
8486
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"},{"e","f"}}');
8587
INSERT INTO domarrtest values ('{2,2}', '{{"a"},{"c"}}');
8688
INSERT INTO domarrtest values (NULL, '{{"a","b","c"},{"d","e","f"}}');
89+
INSERT INTO domarrtest values (NULL, '{{"toolong","b","c"},{"d","e","f"}}');
90+
ERROR: value too long for type character varying(4)
8791
select * from domarrtest;
88-
testint4arr | testtextarr
92+
testint4arr | testchar4arr
8993
---------------+---------------------
9094
{2,2} | {{a,b},{c,d}}
9195
{{2,2},{2,2}} | {{a,b}}
@@ -94,19 +98,35 @@ select * from domarrtest;
9498
| {{a,b,c},{d,e,f}}
9599
(5 rows)
96100

97-
select testint4arr[1], testtextarr[2:2] from domarrtest;
98-
testint4arr | testtextarr
99-
-------------+-------------
101+
select testint4arr[1], testchar4arr[2:2] from domarrtest;
102+
testint4arr | testchar4arr
103+
-------------+--------------
100104
2 | {{c,d}}
101105
| {}
102106
2 | {{c,d}}
103107
2 | {{c}}
104108
| {{d,e,f}}
105109
(5 rows)
106110

111+
COPY domarrtest FROM stdin;
112+
COPY domarrtest FROM stdin; -- fail
113+
ERROR: value too long for type character varying(4)
114+
CONTEXT: COPY domarrtest, line 1, column testchar4arr: "{qwerty,w,e}"
115+
select * from domarrtest;
116+
testint4arr | testchar4arr
117+
---------------+---------------------
118+
{2,2} | {{a,b},{c,d}}
119+
{{2,2},{2,2}} | {{a,b}}
120+
{2,2} | {{a,b},{c,d},{e,f}}
121+
{2,2} | {{a},{c}}
122+
| {{a,b,c},{d,e,f}}
123+
{3,4} | {q,w,e}
124+
|
125+
(7 rows)
126+
107127
drop table domarrtest;
108128
drop domain domainint4arr restrict;
109-
drop domain domaintextarr restrict;
129+
drop domain domainchar4arr restrict;
110130
create domain dnotnull varchar(15) NOT NULL;
111131
create domain dnull varchar(15);
112132
create domain dcheck varchar(15) NOT NULL CHECK (VALUE = 'a' OR VALUE = 'c' OR VALUE = 'd');

src/test/regress/sql/domain.sql

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ drop domain domaindroptest cascade;
1717
drop domain domaindroptest cascade;
1818

1919

20-
-- TEST Domains.
20+
-- Test domain input.
21+
22+
-- Note: the point of checking both INSERT and COPY FROM is that INSERT
23+
-- exercises CoerceToDomain while COPY exercises domain_in.
2124

2225
create domain domainvarchar varchar(5);
2326
create domain domainnumeric numeric(8,2);
@@ -62,25 +65,38 @@ drop domain domainint4 restrict;
6265
drop domain domaintext;
6366

6467

65-
-- Array Test
68+
-- Test domains over array types
69+
6670
create domain domainint4arr int4[1];
67-
create domain domaintextarr text[2][3];
71+
create domain domainchar4arr varchar(4)[2][3];
6872

6973
create table domarrtest
7074
( testint4arr domainint4arr
71-
, testtextarr domaintextarr
75+
, testchar4arr domainchar4arr
7276
);
7377
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"}}');
7478
INSERT INTO domarrtest values ('{{2,2},{2,2}}', '{{"a","b"}}');
7579
INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"},{"e","f"}}');
7680
INSERT INTO domarrtest values ('{2,2}', '{{"a"},{"c"}}');
7781
INSERT INTO domarrtest values (NULL, '{{"a","b","c"},{"d","e","f"}}');
82+
INSERT INTO domarrtest values (NULL, '{{"toolong","b","c"},{"d","e","f"}}');
83+
select * from domarrtest;
84+
select testint4arr[1], testchar4arr[2:2] from domarrtest;
85+
86+
COPY domarrtest FROM stdin;
87+
{3,4} {q,w,e}
88+
\N \N
89+
\.
90+
91+
COPY domarrtest FROM stdin; -- fail
92+
{3,4} {qwerty,w,e}
93+
\.
94+
7895
select * from domarrtest;
79-
select testint4arr[1], testtextarr[2:2] from domarrtest;
8096

8197
drop table domarrtest;
8298
drop domain domainint4arr restrict;
83-
drop domain domaintextarr restrict;
99+
drop domain domainchar4arr restrict;
84100

85101

86102
create domain dnotnull varchar(15) NOT NULL;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy