Re: wrong field in example

From: Yaroslav Saburov <y(dot)saburov(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, PostgreSQL Documentation <pgsql-docs(at)lists(dot)postgresql(dot)org>
Subject: Re: wrong field in example
Date: 2024-07-24 16:31:55
Message-ID: 8EF645CB-0AE2-4113-80CB-97720A74939E@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

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 <tgl(at)sss(dot)pgh(dot)pa(dot)us> пише:
>
> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)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

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message PG Doc comments form 2024-07-25 03:47:28 Typo in 15.3.4
Previous Message Tom Lane 2024-07-24 16:17:30 Re: wrong field in example