Re: Questions about parsing boolean and casting to anyelement

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Questions about parsing boolean and casting to anyelement
Дата
Msg-id 24487.1234913966@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Questions about parsing boolean and casting to anyelement  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Restore frozen xids for binary upgrades
Следующее
От: Tom Lane
Дата:
Сообщение: Re: vacuumdb --freeze