pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Sébastien Lardière <sebastien@lardiere.net>
Cc: pgsql-bugs@lists.postgresql.org
Cc: fluca1978@gmail.com
Subject: Re: Recursive CTE and collation
Date: Fri, 14 Jun 2019 11:19:29 -0400
Message-ID: <27731.1560525569@sss.pgh.pa.us> (raw)
In-Reply-To: <4d73f7e5-a64d-2a9c-9148-09176d6261fb@lardiere.net>
References: <97aa6131-7f79-a29b-1bb3-7e87b2f4f50c@lardiere.net>
	<28491.1560519572@sss.pgh.pa.us>
	<4d73f7e5-a64d-2a9c-9148-09176d6261fb@lardiere.net>

=?UTF-8?Q?S=c3=a9bastien_Lardi=c3=a8re?= <sebastien@lardiere.net> writes:
> On 14/06/2019 15:39, Tom Lane wrote:
>> I notice that it does work in a regular union:
>> regression=# select null::text union select null::name collate "C";
>> but I believe that recursive union is intentionally stricter.

I took a closer look at the code to refresh my memory about this,
and the actual rule for recursive unions is that the output of
the union has to have the same column types/collations that were
inferred from the non-recursive (first) side alone.  This is needed
because when we do parse analysis of the recursive side, those
types/collations are what we'll assume for any references to the
recursive union's result.  It's too late to change those decisions
when we find out what the UNION actually produces.

(You could imagine doing the parse analysis more than once in hopes
of arriving at a stable result, but ugh.  I don't think the SQL spec
requires any such thing.)

So what we have here is that in v11, you were union'ing text (collation
"default") with name (no collation), and you got text with collation
"default" because text is a preferred type over name.  So it worked OK.
In v12, you're union'ing text (collation "default") with name (collation
"C").  You still get text output because text is still the preferred
type, but the collation resolution rules consider "default" to not be
preferred so the chosen output collation is "C".  Ooops.

Obviously there's more than one way you could fix the mismatch, but
I think that changing the NULL to type "name" is the nicest.

			regards, tom lane





view thread (5+ messages)  latest in thread

Message-ID: <27731.1560525569@sss.pgh.pa.us>
Permalink:  ../27731.1560525569@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/27731.1560525569@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 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: tgl@sss.pgh.pa.us, sebastien@lardiere.net, fluca1978@gmail.com
  Subject: Re: Recursive CTE and collation
  In-Reply-To: <27731.1560525569@sss.pgh.pa.us>
  References: <97aa6131-7f79-a29b-1bb3-7e87b2f4f50c@lardiere.net> <28491.1560519572@sss.pgh.pa.us> <4d73f7e5-a64d-2a9c-9148-09176d6261fb@lardiere.net> <27731.1560525569@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