From: Jeff Davis <pgsql@j-davis.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: [BUGS] Failure to coerce unknown type to specific type
Date: Wed, 22 Apr 2015 23:26:43 -0700
Message-ID: <1429770403.4604.22.camel@jeff-desktop> (raw)
In-Reply-To: <CAKFQuwYHOyFnKxmOeiBw4pxgn9oLJidaQeo48gKnAsUXucnnuQ@mail.gmail.com>
References: <CAMp0ubdECGUJWpQKyUM36PxQWoKe0VfTbHGHgn+w2H_5q1Nmow@mail.gmail.com>
<1430.1428543112@sss.pgh.pa.us>
<1428560300.2845.45.camel@jeff-desktop>
<CAMp0ubdVJAC+yO5XqU=M08WyXX19jnk9r2Faeo5W-SVDWAKzZA@mail.gmail.com>
<CAKFQuwYHOyFnKxmOeiBw4pxgn9oLJidaQeo48gKnAsUXucnnuQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On Wed, 2015-04-22 at 20:35 -0700, David G. Johnston wrote:
> But the fact that column "b" has the data type "unknown" is only a
> warning - not an error.
>
I get an error:
postgres=# SELECT ' '::text = 'a';
?column?
----------
f
(1 row)
postgres=# SELECT a=b FROM (SELECT ''::text, ' ') x(a,b);
ERROR: failed to find conversion function from unknown to text
So that means the column reference "b" is treated differently than the
literal. Here I don't mean a reference to an actual column of a real
table, just an identifier ("b") that parses as a columnref.
Creating the table gives you a warning (not an error), but I think that
was a poor example for me to choose, and not important to my point.
>
> This seems to be a case of the common problem (or, at least recently
> mentioned) where type conversion only deals with data and not context.
>
>
> http://www.postgresql.org/message-id/CADx9qBmVPQvSH3
> +2cH4cwwPmphW1mE18e=WUmLFUC-QZ-t7Q6Q@mail.gmail.com
>
>
I think that is a different problem. That's a runtime type conversion
error (execution time), and I'm talking about something happening at
parse analysis time.
>
> but this too works - which is why the implicit cast concept above
> fails (I'm leaving it since the thought process may help in
> understanding):
>
>
> SELECT 1 = '1';
>
>
> From which I infer that an unknown literal is allowed to be fed
> directly into a type's input function to facilitate a direct coercion.
Yes, I believe that's what's happening. When we use an unknown literal,
it's acting more like a value constructor and will pass it to the type
input function. When it's a columnref, even if unknown, it tries to cast
it and fails.
But that is very confusing. In the example at the top of this email, it
seems like the second query should be equivalent to the first, or even
that postgres should be able to rewrite the second into the first. But
the second query fails where the first succeeds.
> At this point...backward compatibility?
Backwards compatibility of what queries? I guess the ones that return
unknowns to the client or create tables with unknown columns?
> create table a(u) as select '1';
>
>
> WARNING: "column "u" has type "unknown"
> DETAIL: Proceeding with relation creation anyway.
>
>
> Related question: was there ever a time when the above failed instead
> of just supplying a warning?
Not that I recall.
> My gut reaction is if you feel strongly enough to add some additional
> documentation or warnings/hints/details related to this topic they
> probably would get put in; but disallowing "unknown" as first-class
> type is likely to fail to pass a cost-benefit evaluation.
I'm not proposing that we eliminate unknown. I just think columnrefs and
literals should behave consistently. If we really don't want unknown
columnrefs, it seems like we could at least throw a better error.
If we were starting from scratch, I'd also not return unknown to the
client, but we have to worry about the backwards compatibility.
> Distinguishing between "untyped" literals and "unknown type" literals
> seems promising concept to aid in understanding the difference in the
> face of not being able (or wanting) to actually change the behavior.
Not sure I understand that proposal, can you elaborate?
Regards,
Jeff Davis
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: pgsql@j-davis.com, david.g.johnston@gmail.com, tgl@sss.pgh.pa.us, pgsql-hackers@postgresql.org
Subject: Re: [BUGS] Failure to coerce unknown type to specific type
In-Reply-To: <1429770403.4604.22.camel@jeff-desktop>
References: <CAMp0ubdECGUJWpQKyUM36PxQWoKe0VfTbHGHgn+w2H_5q1Nmow@mail.gmail.com> <1430.1428543112@sss.pgh.pa.us> <1428560300.2845.45.camel@jeff-desktop> <CAMp0ubdVJAC+yO5XqU=M08WyXX19jnk9r2Faeo5W-SVDWAKzZA@mail.gmail.com> <CAKFQuwYHOyFnKxmOeiBw4pxgn9oLJidaQeo48gKnAsUXucnnuQ@mail.gmail.com> <1429770403.4604.22.camel@jeff-desktop>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox