Re: BUG #18173: ERROR: could not identify a comparison function for type unknown

From: 下雨天 <409800246(at)qq(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #18173: ERROR: could not identify a comparison function for type unknown
Date: 2023-11-01 07:44:03
Message-ID: tencent_7267697C6B25F36E2F1ECDBD0C01B6F68409@qq.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Perhaps you're right.&nbsp;
Different databases have their unique characteristics, and there is indeed no need to be compatible with Oracle.
At least in the specific case of DISTINCT, it indeed increases the workload for users migrating from Oracle to PostgreSQL, which seems&nbsp;inevitable at present.

Thanks!

------------------&nbsp;Original&nbsp;------------------
From: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us&gt;;
Date:&nbsp;Tue, Oct 31, 2023 10:51 PM
To:&nbsp;"Laurenz Albe"<laurenz(dot)albe(at)cybertec(dot)at&gt;;
Cc:&nbsp;"下雨天"<409800246(at)qq(dot)com&gt;;"pgsql-bugs"<pgsql-bugs(at)lists(dot)postgresql(dot)org&gt;;
Subject:&nbsp;Re: BUG #18173: ERROR: could not identify a comparison function for type unknown

Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at&gt; writes:
&gt; On Mon, 2023-10-30 at 13:24 +0000, PG Bug reporting form wrote:
&gt;&gt; postgres=# select distinct (id,name,'D3Q84xpymM',123,'123') from test_v;
&gt;&gt; ERROR:&nbsp; could not identify a comparison function for type unknown

&gt; This is not a bug.&nbsp; You probably want to remove the parentheses.

It is a bit inconsistent that we allow

select distinct id,name,'D3Q84xpymM',123,'123' from test_v;

and

select (id,name,'D3Q84xpymM',123,'123') from test_v;

but not the above.&nbsp; Poking around, I discovered a related failure:

select ((id,name,'D3Q84xpymM',123,'123')).f3 from test_v;
ERROR:&nbsp; failed to find conversion function from unknown to text

That happens because at the end of parsing we apply
resolveTargetListUnknowns, which sees that there's an UNKNOWN
output column and tries to coerce it to text, but can't since
it's not a plain literal.

So maybe there is a case for forcing unknowns to text in the
input list of a RowExpr.&nbsp; You could argue that a RowExpr is
morally the same thing as a SELECT list, so this would have
some consistency to it.&nbsp; Nonetheless, it's a rather big
semantics change and I wonder what it might break.&nbsp; Notably,
in the context

row(...,'foo',...)::somerowtype

currently the cast to somerowtype will see an unknown literal
and do the right thing, whereas maybe with text input it might
do something surprising (and in any case we'd lose some
efficiency from the extra type coercion).

On the whole, given the lack of complaints for the last couple
of decades, I'm content to say that it's operating as intended.
At best we'd be switching from one nonstandard behavior to
another.&nbsp; ("Oracle does it" doesn't make it standard.)

In any case, I don't like the proposed patch one bit.
Kluging this up in the specific case of DISTINCT is just
adding a wart.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alexander Korotkov 2023-11-01 10:29:12 Re: BUG #18170: Unexpected error: no relation entry for relid 3
Previous Message Andrei Lepikhov 2023-11-01 03:55:45 Re: BUG #18170: Unexpected error: no relation entry for relid 3