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 1o34Lm-0007vD-L2 for pgsql-general@arkaria.postgresql.org; Sun, 19 Jun 2022 23:29:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o34Lj-0003i3-Kl for pgsql-general@arkaria.postgresql.org; Sun, 19 Jun 2022 23:28:59 +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 1o34Lj-0003hm-AS for pgsql-general@lists.postgresql.org; Sun, 19 Jun 2022 23:28:59 +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 1o34LY-0004SV-Va for pgsql-general@lists.postgresql.org; Sun, 19 Jun 2022 23:28:55 +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 25JNSZBp2287378; Sun, 19 Jun 2022 19:28:35 -0400 From: Tom Lane To: Bryn Llewellyn cc: "Peter J. Holzer" , pgsql-general list , "David G. Johnston" Subject: Re: Outer joins and NULLs (old subject "ERROR: failed to find conversion function from key_vals_nn to record[]") In-reply-to: References: Comments: In-reply-to Bryn Llewellyn message dated "Sun, 19 Jun 2022 14:31:11 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2287376.1655681315.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 19 Jun 2022 19:28:35 -0400 Message-ID: <2287377.1655681315@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Bryn Llewellyn writes: > Self-evidently, a view does *not* inherit constraints from the columns o= f its base table(s). Check. > A view on a single table doesn't necessarily inherit the data types of i= ts base table's columns. Rather, the view compilation's analysis is *somet= imes* clever enough to notice when a projected column might have a NULL ev= en when the base column doesn't allow NULLs. In this case, if the base col= umn's data type is (in my example) the domain "text_nn", then the correspo= nding column in the view is given the data type plain "text". My test that= uses a single table shows this. This is nonsense. The parser does not account for domain constraints in that way. It would be incorrect to do so, because then the view's data types could need to change as a consequence of adding/dropping domain constraints. I think that your result is actually just an illustration of the rules in https://www.postgresql.org/docs/current/typeconv-union-case.html about how the output type of a CASE expression is determined --- specifically, that domains are smashed to base types as soon as the CASE arms are discovered to not be all of the same type. regards, tom lane