Handle domains when checking for recursive inclusion of composite types.
authorTom Lane <[email protected]>
Thu, 2 Jun 2011 22:37:57 +0000 (18:37 -0400)
committerTom Lane <[email protected]>
Thu, 2 Jun 2011 22:37:57 +0000 (18:37 -0400)
We need this now because we allow domains over arrays, and we'll probably
allow domains over composites pretty soon, which makes the problem even
more obvious.

Although domains over arrays also exist in previous versions, this does not
need to be back-patched, because the coding used in older versions
successfully "looked through" domains over arrays.  The problem is exposed
by not treating a domain as having a typelem.

Problem identified by Noah Misch, though I did not use his patch, since
it would require additional work to handle domains over composites that
way.  This approach is more future-proof.

src/backend/catalog/heap.c
src/test/regress/expected/alter_table.out
src/test/regress/sql/alter_table.sql

index 71c99318343c4c8f80b03ad237b7943b872769a8..863995714752d7e1528b1e595ed9496595b330c7 100644 (file)
@@ -485,12 +485,19 @@ CheckAttributeType(const char *attname,
                                         errmsg("column \"%s\" has pseudo-type %s",
                                                        attname, format_type_be(atttypid))));
        }
+       else if (att_typtype == TYPTYPE_DOMAIN)
+       {
+               /*
+                * If it's a domain, recurse to check its base type.
+                */
+               CheckAttributeType(attname, getBaseType(atttypid), attcollation,
+                                                  containing_rowtypes,
+                                                  allow_system_table_mods);
+       }
        else if (att_typtype == TYPTYPE_COMPOSITE)
        {
                /*
-                * For a composite type, recurse into its attributes.  You might think
-                * this isn't necessary, but since we allow system catalogs to break
-                * the rule, we have to guard against the case.
+                * For a composite type, recurse into its attributes.
                 */
                Relation        relation;
                TupleDesc       tupdesc;
index 26e7bfd8c2f094214ef43578e4056faf5675ffe7..f84da45de650591f3d6a0e1ced28bb98e8b69431 100644 (file)
@@ -1516,6 +1516,9 @@ alter table recur1 add column f2 recur1; -- fails
 ERROR:  composite type recur1 cannot be made a member of itself
 alter table recur1 add column f2 recur1[]; -- fails
 ERROR:  composite type recur1 cannot be made a member of itself
+create domain array_of_recur1 as recur1[];
+alter table recur1 add column f2 array_of_recur1; -- fails
+ERROR:  composite type recur1 cannot be made a member of itself
 create temp table recur2 (f1 int, f2 recur1);
 alter table recur1 add column f2 recur2; -- fails
 ERROR:  composite type recur1 cannot be made a member of itself
index 0ed16fb7cf94b561cdb76c4e18022df42d35a83b..b5d76ea68e3fbdaf7df00045847fbfa724157f1c 100644 (file)
@@ -1128,6 +1128,8 @@ alter table tab1 alter column b type varchar; -- fails
 create temp table recur1 (f1 int);
 alter table recur1 add column f2 recur1; -- fails
 alter table recur1 add column f2 recur1[]; -- fails
+create domain array_of_recur1 as recur1[];
+alter table recur1 add column f2 array_of_recur1; -- fails
 create temp table recur2 (f1 int, f2 recur1);
 alter table recur1 add column f2 recur2; -- fails
 alter table recur1 add column f2 int;