]> granicus.if.org Git - postgresql/commitdiff
Fix 8.2 breakage of domains over array types, and add a regression test case
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 19 Mar 2007 16:30:32 +0000 (16:30 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 19 Mar 2007 16:30:32 +0000 (16:30 +0000)
to cover it.  Per report from Anton Pikhteryev.

src/backend/utils/cache/lsyscache.c
src/test/regress/expected/domain.out
src/test/regress/sql/domain.sql

index 6df288da45fed20202e9eb071cf48dd89e99f062..69f1e0c2422bc8ee49507dbde034b87e64cec234 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.149 2007/03/17 00:11:05 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.150 2007/03/19 16:30:31 tgl Exp $
  *
  * NOTES
  *       Eventually, the index information should go through here, too.
@@ -1767,10 +1767,10 @@ getTypeIOParam(HeapTuple typeTuple)
 
        /*
         * Array types get their typelem as parameter; everybody else gets their
-        * own type OID as parameter.  (This is a change from 8.0, in which only
-        * composite types got their own OID as parameter.)
+        * own type OID as parameter.  (As of 8.2, domains must get their own OID
+        * even if their base type is an array.)
         */
-       if (OidIsValid(typeStruct->typelem))
+       if (typeStruct->typtype == 'b' && OidIsValid(typeStruct->typelem))
                return typeStruct->typelem;
        else
                return HeapTupleGetOid(typeTuple);
index 4acaaa4121cd564abde1a8915592ee08e2bd8b6f..e01fc7cadcc1499fc460b7df324529f6b5e5435b 100644 (file)
@@ -15,7 +15,9 @@ NOTICE:  drop cascades to type dependenttypetest
 -- this should fail because already gone
 drop domain domaindroptest cascade;
 ERROR:  type "domaindroptest" does not exist
--- TEST Domains.
+-- Test domain input.
+-- Note: the point of checking both INSERT and COPY FROM is that INSERT
+-- exercises CoerceToDomain while COPY exercises domain_in.
 create domain domainvarchar varchar(5);
 create domain domainnumeric numeric(8,2);
 create domain domainint4 int4;
@@ -72,20 +74,22 @@ drop domain domainvarchar restrict;
 drop domain domainnumeric restrict;
 drop domain domainint4 restrict;
 drop domain domaintext;
--- Array Test
+-- Test domains over array types
 create domain domainint4arr int4[1];
-create domain domaintextarr text[2][3];
+create domain domainchar4arr varchar(4)[2][3];
 create table domarrtest
            ( testint4arr domainint4arr
-           , testtextarr domaintextarr
+           , testchar4arr domainchar4arr
             );
 INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"}}');
 INSERT INTO domarrtest values ('{{2,2},{2,2}}', '{{"a","b"}}');
 INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"},{"e","f"}}');
 INSERT INTO domarrtest values ('{2,2}', '{{"a"},{"c"}}');
 INSERT INTO domarrtest values (NULL, '{{"a","b","c"},{"d","e","f"}}');
+INSERT INTO domarrtest values (NULL, '{{"toolong","b","c"},{"d","e","f"}}');
+ERROR:  value too long for type character varying(4)
 select * from domarrtest;
-  testint4arr  |     testtextarr     
+  testint4arr  |    testchar4arr     
 ---------------+---------------------
  {2,2}         | {{a,b},{c,d}}
  {{2,2},{2,2}} | {{a,b}}
@@ -94,9 +98,9 @@ select * from domarrtest;
                | {{a,b,c},{d,e,f}}
 (5 rows)
 
-select testint4arr[1], testtextarr[2:2] from domarrtest;
- testint4arr | testtextarr 
--------------+-------------
+select testint4arr[1], testchar4arr[2:2] from domarrtest;
+ testint4arr | testchar4arr 
+-------------+--------------
            2 | {{c,d}}
              | {}
            2 | {{c,d}}
@@ -104,9 +108,25 @@ select testint4arr[1], testtextarr[2:2] from domarrtest;
              | {{d,e,f}}
 (5 rows)
 
+COPY domarrtest FROM stdin;
+COPY domarrtest FROM stdin;    -- fail
+ERROR:  value too long for type character varying(4)
+CONTEXT:  COPY domarrtest, line 1, column testchar4arr: "{qwerty,w,e}"
+select * from domarrtest;
+  testint4arr  |    testchar4arr     
+---------------+---------------------
+ {2,2}         | {{a,b},{c,d}}
+ {{2,2},{2,2}} | {{a,b}}
+ {2,2}         | {{a,b},{c,d},{e,f}}
+ {2,2}         | {{a},{c}}
+               | {{a,b,c},{d,e,f}}
+ {3,4}         | {q,w,e}
+               | 
+(7 rows)
+
 drop table domarrtest;
 drop domain domainint4arr restrict;
-drop domain domaintextarr restrict;
+drop domain domainchar4arr restrict;
 create domain dnotnull varchar(15) NOT NULL;
 create domain dnull    varchar(15);
 create domain dcheck   varchar(15) NOT NULL CHECK (VALUE = 'a' OR VALUE = 'c' OR VALUE = 'd');
index 411d64648a6d7c0eb3a3a33654ee6c71af1ca1ac..4e103172edfb2d11bd4e64a5863f66ae037957d0 100644 (file)
@@ -17,7 +17,10 @@ drop domain domaindroptest cascade;
 drop domain domaindroptest cascade;
 
 
--- TEST Domains.
+-- Test domain input.
+
+-- Note: the point of checking both INSERT and COPY FROM is that INSERT
+-- exercises CoerceToDomain while COPY exercises domain_in.
 
 create domain domainvarchar varchar(5);
 create domain domainnumeric numeric(8,2);
@@ -62,25 +65,38 @@ drop domain domainint4 restrict;
 drop domain domaintext;
 
 
--- Array Test
+-- Test domains over array types
+
 create domain domainint4arr int4[1];
-create domain domaintextarr text[2][3];
+create domain domainchar4arr varchar(4)[2][3];
 
 create table domarrtest
            ( testint4arr domainint4arr
-           , testtextarr domaintextarr
+           , testchar4arr domainchar4arr
             );
 INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"}}');
 INSERT INTO domarrtest values ('{{2,2},{2,2}}', '{{"a","b"}}');
 INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"},{"e","f"}}');
 INSERT INTO domarrtest values ('{2,2}', '{{"a"},{"c"}}');
 INSERT INTO domarrtest values (NULL, '{{"a","b","c"},{"d","e","f"}}');
+INSERT INTO domarrtest values (NULL, '{{"toolong","b","c"},{"d","e","f"}}');
+select * from domarrtest;
+select testint4arr[1], testchar4arr[2:2] from domarrtest;
+
+COPY domarrtest FROM stdin;
+{3,4}  {q,w,e}
+\N     \N
+\.
+
+COPY domarrtest FROM stdin;    -- fail
+{3,4}  {qwerty,w,e}
+\.
+
 select * from domarrtest;
-select testint4arr[1], testtextarr[2:2] from domarrtest;
 
 drop table domarrtest;
 drop domain domainint4arr restrict;
-drop domain domaintextarr restrict;
+drop domain domainchar4arr restrict;
 
 
 create domain dnotnull varchar(15) NOT NULL;