I want to dump the whole content of a table, ordered by its primary key. Intuitively, I would like to do a
SELECT * FROM %table_name% ORDER BY %primary_key_of(table_name)%;
This would be run by an external tool, knowing the list of the tables, but not knowing their primary keys.
If there is no better option, we can assume that all primary keys are single-column.
I am using PostgreSQL-9.5, but an upgrade is possible.
Best Answer
I believe that if you put a clustered index on your primary key, then PG will use that by default. Untested hypothesis :)
According to https://www.postgresql.org/docs/current/static/sql-cluster.html