Add example to sort results by two composite types

Поиск
Список
Период
Сортировка
Искать

Add example to sort results by two composite types

От:
PG Doc comments form <noreply@postgresql.org>
Дата:
The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/17/rowtypes.html
Description:

The doc has example:
All of these ORDER BY clauses specify the row's composite value, resulting
in sorting the rows according to the rules described in Section 9.25.6.
However, if inventory_item contained a column named c, the first case would
be different from the others, as it would mean to sort by that column only.
Given the column names previously shown, these queries are also equivalent
to those above:

SELECT * FROM inventory_item c ORDER BY ROW(c.name, c.supplier_id, c.price);
SELECT * FROM inventory_item c ORDER BY (c.name, c.supplier_id, c.price);

I suggest to extend the example to sort results by first composite type and
then by the second:
SELECT * FROM invertory_type t, inventory_item c ORDER BY (c.name,
c.supplier_id, c.price), (t.name, t.value);

Though I did not checked this if it possible or not. It would be nice to
have it documented.

Thank you.

Re: Add example to sort results by two composite types

От:
"David G. Johnston" <david.g.johnston@gmail.com>
Дата:
On Sunday, July 13, 2025, PG Doc comments form <noreply@postgresql.org> wrote:

I suggest to extend the example to sort results by first composite type and
then by the second:
SELECT * FROM invertory_type t, inventory_item c ORDER BY (c.name,
c.supplier_id, c.price), (t.name, t.value);

Though I did not checked this if it possible or not. It would be nice to
have it documented.

What new information does that add or uncertainty does it clarify?  This isn’t a section teaching order by - the reader is expected to already understand that an order by clause can accept two column names and how those are treated (i.e., ties among the first are broken by the second).  This is a section about how within that structure the comparisons happen.  A single column suffices to make that explanation.

David J.

FAQ