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 1mYutk-0004hI-U9 for pgsql-bugs@arkaria.postgresql.org; Fri, 08 Oct 2021 18:47:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mYutj-0006iO-J2 for pgsql-bugs@arkaria.postgresql.org; Fri, 08 Oct 2021 18:47:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mYtln-00070q-PO for pgsql-bugs@lists.postgresql.org; Fri, 08 Oct 2021 17:34:55 +0000 Received: from sender4-op-o11.zoho.com ([136.143.188.11]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mYtll-0005WI-Fb for pgsql-bugs@lists.postgresql.org; Fri, 08 Oct 2021 17:34:54 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1633714482; cv=none; d=zohomail.com; s=zohoarc; b=hiZol1LCLvVjTfvWSnJv/vzy7XQ2CslCitVfP4zBTDNsSJtsEkNOmRaH8PL5UH29k12qxq8JClwGutZsSkHVy8/zxflIG0JmUmSC7mBgOaSDK8cZWineO6ib8ArwNChv1rz84ojtZoyrRE/hXjQw5aZW7zbJZcg1MbZXqIhSbhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633714482; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=YDpyVIG2f2EBqLUjtsHV4Khef0uoXi0fmAXSi9bnAXM=; b=O8jK/IgT2Z7bK8AjUrUqVfZvUq5Tit0tweGuC4xZmuwli2EMaI7b1IF5heABiYET6rcttT371GP6BkBQQiunqw8Kvsg7MQZa76CVOeoyxnOAHRySyszGAm2VOmR8YW98DZmYUs5wIwADdq6IFLCp9/UxuJVUGXl8rCTZJuc2n/w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=yottadb.com; spf=pass smtp.mailfrom=nars@yottadb.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1633714482; s=bam5eec4; d=yottadb.com; i=nars@yottadb.com; h=From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=YDpyVIG2f2EBqLUjtsHV4Khef0uoXi0fmAXSi9bnAXM=; b=RPpX6CEwFozEW+emxLqFeWJoB3JZswslvReSu7vWHM4TidTRsAC0mj1akIJzvwSG Fay9Br4CzBKsSpjnrJ18xY9lTZx2YNDJt/pCjCBRfQ7rD9MVBSLePvhOABucFLbGfcF 4cc8bwYIXc5cFbuJ5LrQlQSnRPjh3AcbPeqto0vc= Received: from NARSWIN10 (static-71-162-243-192.phlapa.fios.verizon.net [71.162.243.192]) by mx.zohomail.com with SMTPS id 1633714480927330.4877515836939; Fri, 8 Oct 2021 10:34:40 -0700 (PDT) From: "Narayanan Iyer" To: "'Tom Lane'" Cc: , References: <0e0301d7bc59$a1e416b0$e5ac4410$@yottadb.com> <236280.1633710901@sss.pgh.pa.us> In-Reply-To: <236280.1633710901@sss.pgh.pa.us> Subject: RE: GROUP BY using tablename.* does not work if tablename has 1 column with NULL values Date: Fri, 8 Oct 2021 13:34:37 -0400 Message-ID: <0f6701d7bc6a$c52e7370$4f8b5a50$@yottadb.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQFDuJQIdzhfXF3+VBqkdhB2CmBVAgGZWxM2rOSUybA= Content-Language: en-us X-Antivirus: Avast (VPS 211008-0, 10/7/2021), Outbound message X-Antivirus-Status: Clean X-ZohoMailClient: External List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tom, thank you for the detailed response. Did not realize t1.* creates a = ROW(NULL) value whereas t1.lastName does not. That explains the = difference. I also did not know the ::record syntax. Nice tool. Thanks. I agree it is not a bug. Please close the issue. Narayanan. -----Original Message----- From: Tom Lane [mailto:tgl@sss.pgh.pa.us]=20 Sent: Friday, October 8, 2021 12:35 PM To: Narayanan Iyer Cc: pgsql-bugs@lists.postgresql.org; support@yottadb.com Subject: Re: GROUP BY using tablename.* does not work if tablename has 1 = column with NULL values "Narayanan Iyer" writes: > In the below example, t1 points to a table with just 1 column = (lastName) and so I expect the 2 SELECT queries (pasted below) using = t1.lastName or t1.* syntax to produce the exact same results. But the = latter produces one extra row of output (3 rows vs 2 rows). I don't see any bug here. If you take out the grouping it's a bit = easier to see what's going on: SELECT *, t1.*::record FROM tmp t2 LEFT JOIN (SELECT lastName FROM tmp) = AS t1 ON (t2.firstName <=3D 'Acid'); id | firstname | lastname | lastname | t1 =20 ----+-----------+----------+----------+-------- 1 | Acid | Burn | Burn | (Burn) 1 | Acid | Burn | | () 2 | Joey | | |=20 (3 rows) The first row comes from joining t2 Acid,Burn to t1 Acid,Burn. The second row comes from joining t2 Acid,Burn to t1 Joey,NULL. The third row comes from failing to join t2 Joey,NULL to anything. So in the second row, there is a matched t1 row, and t1.* therefore represents a non-null composite value that happens to contain one null field. In the third row, there is no matched t1 row at all, so we consider that t1.* is a composite NULL, which is different from a composite containing NULL fields. You can argue about whether composite NULL ought to be considered identical to ROW(NULL). But there are a lot of contexts where that would be a bad idea, and very few where it'd be good. =20 > It seems like a Postgres bug to me. Not sure if there is a Postgres = setting that I need to enable in order to avoid this discrepancy. You might be able to get the results you want by explicitly converting to row-containing-nulls, which is not very hard: SELECT *, row(t1.*) FROM tmp t2 LEFT JOIN (SELECT lastName FROM tmp) AS = t1 ON (t2.firstName <=3D 'Acid'); id | firstname | lastname | lastname | row =20 ----+-----------+----------+----------+-------- 1 | Acid | Burn | Burn | (Burn) 1 | Acid | Burn | | () 2 | Joey | | | () (3 rows) regards, tom lane