Skip to content

Commit 63e98b5

Browse files
committed
Coercion sanity check in ri_HashCompareOp failed to allow for enums, as per
example from Rod Taylor. On reflection the correct test here is for any polymorphic type, not specifically ANYARRAY as in the original coding.
1 parent 2dad10f commit 63e98b5

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/backend/commands/tablecmds.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.254 2008/05/16 23:36:04 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.255 2008/05/19 04:14:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -4377,11 +4377,11 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel,
43774377
/*
43784378
* Otherwise, look for an implicit cast from the FK type to the
43794379
* opcintype, and if found, use the primary equality operator.
4380-
* This is a bit tricky because opcintype might be a generic type
4381-
* such as ANYARRAY, and so what we have to test is whether the
4382-
* two actual column types can be concurrently cast to that type.
4383-
* (Otherwise, we'd fail to reject combinations such as int[] and
4384-
* point[].)
4380+
* This is a bit tricky because opcintype might be a polymorphic
4381+
* type such as ANYARRAY or ANYENUM; so what we have to test is
4382+
* whether the two actual column types can be concurrently cast to
4383+
* that type. (Otherwise, we'd fail to reject combinations such
4384+
* as int[] and point[].)
43854385
*/
43864386
Oid input_typeids[2];
43874387
Oid target_typeids[2];

src/backend/utils/adt/ri_triggers.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
1717
*
18-
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.108 2008/05/12 20:02:02 alvherre Exp $
18+
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.109 2008/05/19 04:14:24 tgl Exp $
1919
*
2020
* ----------
2121
*/
@@ -3938,8 +3938,12 @@ ri_HashCompareOp(Oid eq_opr, Oid typeid)
39383938
if (pathtype != COERCION_PATH_FUNC &&
39393939
pathtype != COERCION_PATH_RELABELTYPE)
39403940
{
3941-
/* If target is ANYARRAY, assume it's OK, else punt. */
3942-
if (lefttype != ANYARRAYOID)
3941+
/*
3942+
* The declared input type of the eq_opr might be a
3943+
* polymorphic type such as ANYARRAY or ANYENUM. If so,
3944+
* assume the coercion is valid; otherwise complain.
3945+
*/
3946+
if (!IsPolymorphicType(lefttype))
39433947
elog(ERROR, "no conversion function from %s to %s",
39443948
format_type_be(typeid),
39453949
format_type_be(lefttype));

0 commit comments

Comments
 (0)