Add example to sort results by two composite types
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.
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.
<div>I never saw such examples before and never thought that I can pass two composite types into ORDER BY clause. Because this section is about composite types, I found it could be useful to highlight that possibility. Otherwise it is too implicit. at least for not so experienced users like me.</div><div> </div><div> </div><div><br /></div><div><br /></div><div>----------------</div>
<div>Кому: kes-kes@yandex.ru (kes-kes@yandex.ru), pgsql-docs@lists.postgresql.org (pgsql-docs@lists.postgresql.org);<br /></div>
<div>Тема: Add example to sort results by two composite types;<br /></div>
<div>14.07.2025, 16:58, "David G. Johnston" <david.g.johnston@gmail.com>:<br /></div>
<blockquote>On Sunday, July 13, 2025, PG Doc comments form <<a href="mailto:noreply@postgresql.org">noreply@postgresql.org</a>> wrote:<br /><blockquote class="f13ca48719c8a60033905b23b39675agmail_quote" style="border-left-color:#ccc;border-left-style:solid;border-left-width:1px;margin:0 0 0 0.8ex;padding-left:1ex"><br />
I suggest to extend the example to sort results by first composite type and<br />
then by the second:<br />
SELECT * FROM invertory_type t, inventory_item c ORDER BY (<a href="http://c.name/" target="_blank">c.name</a>,<br />
c.supplier_id, c.price), (<a href="http://t.name/" target="_blank">t.name</a>, t.value);<br />
<br />
Though I did not checked this if it possible or not. It would be nice to<br />
have it documented.<br />
</blockquote><div><br /></div><div>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.</div><div><br /></div><div>David J.</div><div><br /></div>
</blockquote>