Thread: BUG #4182: Enum in Foreign Key broken

BUG #4182: Enum in Foreign Key broken

From
"Rod Taylor"
Date:
The following bug has been logged online:

Bug reference:      4182
Logged by:          Rod Taylor
Email address:      rod.taylor@gmail.com
PostgreSQL version: 8.3.1
Operating system:   amd64-portbld-freebsd7.0, compiled by GCC cc (GCC) 4.2.1
20070719  [FreeBSD]
Description:        Enum in Foreign Key broken
Details:

The Update in the below script results in the following
ERROR:  no conversion function from some_enum to anyenum




CREATE TYPE some_enum AS ENUM('Value 1', 'Value 2');
CREATE TABLE t1
( col1 varchar(10)
, col2 some_enum
, testboolean boolean
, PRIMARY KEY(col1, col2)
);
CREATE TABLE t2
( col1 varchar(10)
, col2 some_enum
, PRIMARY KEY(col1, col2)
, FOREIGN KEY (col1, col2) REFERENCES t1(col1, col2) on update cascade on
delete restrict
);

INSERT INTO t1 VALUES ('varcharval', 'Value 1');
INSERT INTO t1 VALUES ('varcharval', 'Value 2');

INSERT INTO t2 VALUES ('varcharval', 'Value 1');

UPDATE t1 SET testboolean = false;
-- ERROR:  no conversion function from some_enum to anyenum

Re: BUG #4182: Enum in Foreign Key broken

From
Tom Lane
Date:
"Rod Taylor" <rod.taylor@gmail.com> writes:
> The Update in the below script results in the following
> ERROR:  no conversion function from some_enum to anyenum

This is coming from

            if (pathtype != COERCION_PATH_FUNC &&
                pathtype != COERCION_PATH_RELABELTYPE)
            {
                /* If target is ANYARRAY, assume it's OK, else punt. */
                if (lefttype != ANYARRAYOID)
                    elog(ERROR, "no conversion function from %s to %s",
                         format_type_be(typeid),
                         format_type_be(lefttype));
            }

I suspect this code needs to make an exception for ANYENUM as well, but
no time to look closely right now.

            regards, tom lane