pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Pg Docs <pgsql-docs@lists.postgresql.org>
Subject: Re: Inaccurate description of UNION/CASE/etc type selection
Date: Sun, 16 Aug 2020 20:32:46 -0400
Message-ID: <1031918.1597624366@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwbn05z25KPPAwwA+nqvyb_3eqLM+Q4Awu==9bdVJhum8A@mail.gmail.com>
References: <1019930.1597613200@sss.pgh.pa.us>
	<CAKFQuwbn05z25KPPAwwA+nqvyb_3eqLM+Q4Awu==9bdVJhum8A@mail.gmail.com>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Sun, Aug 16, 2020 at 2:26 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> We had a question about why an ARRAY[] construct was resolving the
>> array's type strangely [1].

> In this specific complaint it strikes me as undesirable to have an lossy
> implicit cast from text to name - and if that wasn't present then text
> would have been chosen as expected.

Yeah, in an ideal world maybe, but I don't see us removing that
implicit cast either --- I expect that'd also break a lot of queries.
[ experiments ... actually it might not be that bad ]  But in any case,
that's not very relevant to the documentation problem.

> Seems like 5 and 6 need to be merged - the chosen type is the first one
> that all subsequent types can be implicitly cast to.  We do not guarantee
> that previous types will be implicitly convertible to this type.
> In pseudo-code:
> else if (can_coerce(n->p)) continue /* matches when pispreferred */
> else if (can_coerce(p->n)) "change chosen type"
> else continue /* but now we expect a runtime implicit cast not found error
> */

This formulation fails to account for the pispreferred check, though.
The pseudo-code would be correct if you made the first line be

else if (pispreferred || can_coerce(n->p)) continue

but then it doesn't map neatly to a description that fails to mention
preferred-ness.  (Note that this would be simpler if we could assume
that pispreferred implies that there is a cast from every other category
member type to p.  But there are counterexamples.)

			regards, tom lane





view thread (10+ messages)  latest in thread

Message-ID: <1031918.1597624366@sss.pgh.pa.us>
Permalink:  ../1031918.1597624366@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1031918.1597624366@sss.pgh.pa.us

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, pgsql-docs@lists.postgresql.org
  Subject: Re: Inaccurate description of UNION/CASE/etc type selection
  In-Reply-To: <1031918.1597624366@sss.pgh.pa.us>

* 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