From: | "Narayanan Iyer" <nars(at)yottadb(dot)com> |
---|---|
To: | "'David G(dot) Johnston'" <david(dot)g(dot)johnston(at)gmail(dot)com>, "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | <pgsql-bugs(at)lists(dot)postgresql(dot)org>, <support(at)yottadb(dot)com> |
Subject: | RE: GROUP BY using tablename.* does not work if tablename has 1 column with NULL values |
Date: | 2021-10-08 17:37:19 |
Message-ID: | 0f6b01d7bc6b$25561500$70023f00$@yottadb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
David,
This query was the simplest I could come up with to illustrate what I thought was the issue. It is not a real world query.
Narayanan.
From: David G. Johnston [mailto:david(dot)g(dot)johnston(at)gmail(dot)com]
Sent: Friday, October 8, 2021 12:51 PM
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Narayanan Iyer <nars(at)yottadb(dot)com>; pgsql-bugs(at)lists(dot)postgresql(dot)org; support(at)yottadb(dot)com
Subject: Re: GROUP BY using tablename.* does not work if tablename has 1 column with NULL values
On Friday, October 8, 2021, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us <mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us> > wrote:
"Narayanan Iyer" <nars(at)yottadb(dot)com <mailto:nars(at)yottadb(dot)com> > 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).
SELECT *, t1.*::record FROM tmp t2 LEFT JOIN (SELECT lastName FROM tmp) AS t1 ON (t2.firstName <= 'Acid');
The third row comes from failing to join t2 Joey,NULL to anything.
This is the part that seems the most unusual (from a “why did you write the query that way” perspective, not the result). A left join’s on clause does not act as a filter for the left side table, so a record with t1.firstName=Joey can still be output. So, on the whole, this is just a poorly written query that takes too much effort for someone to understand due to the non-traditional use of left join and an on clause that doesn’t actually join and oddly decides to restrict the left side.
The fact that nulls are not counted and are also not equal to each other in group by does indeed explain the rest.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Matthew Nelson | 2021-10-08 18:17:16 | Text search prefix matching and stop words |
Previous Message | Narayanan Iyer | 2021-10-08 17:34:37 | RE: GROUP BY using tablename.* does not work if tablename has 1 column with NULL values |