Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k7T5a-00019V-Af for pgsql-docs@arkaria.postgresql.org; Mon, 17 Aug 2020 00:33:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k7T52-0004JP-DQ for pgsql-docs@arkaria.postgresql.org; Mon, 17 Aug 2020 00:32:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k7T52-0004JI-7h for pgsql-docs@lists.postgresql.org; Mon, 17 Aug 2020 00:32:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k7T50-0008TC-Da for pgsql-docs@lists.postgresql.org; Mon, 17 Aug 2020 00:32:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 07H0Wk0Q1031919; Sun, 16 Aug 2020 20:32:46 -0400 From: Tom Lane To: "David G. Johnston" cc: Pg Docs Subject: Re: Inaccurate description of UNION/CASE/etc type selection In-reply-to: References: <1019930.1597613200@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Sun, 16 Aug 2020 17:05:19 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1031917.1597624366.1@sss.pgh.pa.us> Date: Sun, 16 Aug 2020 20:32:46 -0400 Message-ID: <1031918.1597624366@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Sun, Aug 16, 2020 at 2:26 PM Tom Lane 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