Re: Questions about parsing boolean and casting to anyelement - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Questions about parsing boolean and casting to anyelement
Date
Msg-id 24487.1234913966@sss.pgh.pa.us
Whole thread Raw
In response to Re: Questions about parsing boolean and casting to anyelement  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
I wrote:
> In the meantime I'm more convinced than ever that we should throw an
> error for attempting such a cast.  If people are imagining that it will
> do something like that, we need to disillusion them.

BTW, I wrote up what I thought was a trivial patch to make this happen,
and promptly got a regression test failure:
 CREATE TABLE enumtest_child (parent rainbow REFERENCES enumtest_parent); INSERT INTO enumtest_parent VALUES ('red');
INSERTINTO enumtest_child VALUES ('red');
 
+ ERROR:  casting to a polymorphic type such as anyenum is meaningless
+ LINE 1: ... FROM ONLY "public"."enumtest_parent" x WHERE "id"::pg_catal...
+                                                              ^
+ QUERY:  SELECT 1 FROM ONLY "public"."enumtest_parent" x WHERE "id"::pg_catalog.anyenum OPERATOR(pg_catalog.=)
$1::pg_catalog.anyenumFOR SHARE OF x INSERT INTO enumtest_child VALUES ('blue');  -- fail
 

What is happening is that the code to generate RI check queries is
blindly casting to the declared input type of the operator it's
selected, which here is "anyenum = anyenum".  We could easily prevent
it from doing that for polymorphic input types; but since I tripped over
this case almost immediately, I'm wondering what other cases might be
out there that would get broken by throwing this error.

Seeing that this type of confusion hasn't come up before, I think it
might be better to leave things alone here.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Restore frozen xids for binary upgrades
Next
From: Tom Lane
Date:
Subject: Re: vacuumdb --freeze