The function natural_sort_key
allows sorting strings that contain numbers in a more natural way.
SELECT *
FROM …
ORDER BY NATURAL_SORT_KEY(text_col)
Standard SQL uses collations to specify how strings are to be sorted. Known implementations that support naturally sorting collations:
PostgreSQL 10+ with ICU collations (see the “numeric” example in the documentation).
The natural_sort_key
function is not defined by any international standard.
Vendor documentation:
The essence of SQL tuning in 200 pages
Buy on Amazon
(paperback only)
Paperback and PDF also available at Markus’ store.
Markus offers SQL training and consulting for developers working at companies of any size.
Learn more »