[docs] revise ORDER BY documentation

Started by Dian Fayover 2 years ago1 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t49268
psql -h localhost -U postgres

Built from patchset v1 (message #1), October 06, 2026 at 07:59 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t49268_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t49268_1 && git checkout t49268_1

Patchset v1 (message #1) is on t49268_1

Jump to latest
#1Dian Fay
di@nmfay.com

I recently encountered some odd behavior with a query both selecting and
sorting by `random()`. When I posted about it on pgsql-bugs ^1, David
Johnston and Tom Lane provided some very detailed explanations as to
what was happening, but weren't sure whether or where information about
it could live comfortably in the docs. I think it's a useful addition;
it's not an everyday occurrence but I'm very much not the first person
to run into it. After a bit of looking, I think I've found a reasonable
location.

This patch revises
https://www.postgresql.org/docs/current/queries-order.html to discuss
sort expressions and options separately, and fits a caveat based on
Tom's suggested language (with an example) into the former section.

There are a few other minor tweaks included here:

- note that `*` is not an expression
- consolidate output column examples
- mention non-column sort expressions

I did write a query demonstrating the `group by` case Tom mentioned, but
expect that one's a lot less common.

1: /messages/by-id/CZHAF947QQQO.27MAUK2SVMBXW@nmfay.com

Attachments:

t49268_1
0001-Revise-ORDER-BY-documentation.patchtext/x-patch; charset=utf-8; name=0001-Revise-ORDER-BY-documentation.patchDownload+99-63