Re: Inaccurate description of UNION/CASE/etc type selection

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pg Docs <pgsql-docs(at)lists(dot)postgresql(dot)org>
Subject: Re: Inaccurate description of UNION/CASE/etc type selection
Date: 2020-08-17 00:58:00
Message-ID: CAKFQuwZBS2xjTd2dwkNY-az0KGmYFFnU+ebguD73z7ejgy6D=w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Sun, Aug 16, 2020 at 5:32 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> > On Sun, Aug 16, 2020 at 2:26 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> > 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.)
>

I was making that assumption.

In the pseudo-code:

else if (pispreferred) continue; /* never move away from a preferred type */
{the rest of the else ifs from above}

In the docs:

5. If the first non-unknown type is a preferred type it is chosen,
otherwise it is made a candidate, and then,
6. each subsequent type is compared to the current candidate, with a new
candidate being chosen only when there exists a non-mutal implicit cast to
the new type.
6a. If at any point a preferred type is made a candidate then it will be
chosen.

David J.

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message David G. Johnston 2020-08-17 01:06:25 Re: Inaccurate description of UNION/CASE/etc type selection
Previous Message Tom Lane 2020-08-17 00:32:46 Re: Inaccurate description of UNION/CASE/etc type selection