Coercion sanity check in ri_HashCompareOp failed to allow for enums, as per
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 19 May 2008 04:14:33 +0000 (04:14 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 19 May 2008 04:14:33 +0000 (04:14 +0000)
example from Rod Taylor.  On reflection the correct test here is for any
polymorphic type, not specifically ANYARRAY as in the original coding.

src/backend/commands/tablecmds.c
src/backend/utils/adt/ri_triggers.c

index 7d0045eb9fd61345dc198bad69262c69d83828dc..5ef386c000f78c70bbb69488910d2a83f8d75bb8 100644 (file)
@@ -4139,11 +4139,11 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel,
                        /*
                         * Otherwise, look for an implicit cast from the FK type to the
                         * opcintype, and if found, use the primary equality operator.
-                        * This is a bit tricky because opcintype might be a generic type
-                        * such as ANYARRAY, and so what we have to test is whether the
-                        * two actual column types can be concurrently cast to that type.
-                        * (Otherwise, we'd fail to reject combinations such as int[] and
-                        * point[].)
+                        * This is a bit tricky because opcintype might be a polymorphic
+                        * type such as ANYARRAY or ANYENUM; so what we have to test is
+                        * whether the two actual column types can be concurrently cast to
+                        * that type.  (Otherwise, we'd fail to reject combinations such
+                        * as int[] and point[].)
                         */
                        Oid                     input_typeids[2];
                        Oid                     target_typeids[2];
index 9d81c09f803bb046938c2ec14899e14d1c49cc0a..d2b2206d49bd93c5a7a99b49f54c744773e45e45 100644 (file)
@@ -3933,8 +3933,12 @@ ri_HashCompareOp(Oid eq_opr, Oid typeid)
                        if (pathtype != COERCION_PATH_FUNC &&
                                pathtype != COERCION_PATH_RELABELTYPE)
                        {
-                               /* If target is ANYARRAY, assume it's OK, else punt. */
-                               if (lefttype != ANYARRAYOID)
+                               /*
+                                * The declared input type of the eq_opr might be a
+                                * polymorphic type such as ANYARRAY or ANYENUM.  If so,
+                                * assume the coercion is valid; otherwise complain.
+                                */
+                               if (!IsPolymorphicType(lefttype))
                                        elog(ERROR, "no conversion function from %s to %s",
                                                 format_type_be(typeid),
                                                 format_type_be(lefttype));