first query
=> SELECT * FROM test1;
 x | y
---+---
 a | 3
 c | 2
 b | 5
 a | 1
(4 rows)

second query
=> SELECT x FROM test1 GROUP BY x;
 x
---
 a
 b
 c
(3 rows)
In the second query, we could not have written SELECT * FROM test1 GROUP BY x, 
because there is no single value for the column y that could be associated with 
each group. The grouped-by columns can be referenced in the select list since 
they have a single value in each group.




> 24 лип. 2024 р. о 19:17 Tom Lane <t...@sss.pgh.pa.us> пише:
> 
> "David G. Johnston" <david.g.johns...@gmail.com> writes:
>> I don't know that the existing wording is the most clear, but it is correct.
> 
> Perhaps it'd be better to write "... we could not have written
> SELECT x, y FROM test1 GROUP BY x, because ..." ?  The first
> half of the example uses "SELECT *", and this bit was meant
> to be consistent with that; but if the reader is confused about
> how "y" got into the discussion then writing it out explicitly
> should help.
> 
>            regards, tom lane

Reply via email to