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:
You can’t catch up on 20 years of SQL evolution in one day. Subscribe the newsletter via E-Mail, Twitter or RSS to gradually catch up and to keep modern-sql.com on your radar.
The essence of SQL tuning in 200 pages
Buy now!
(paperback and/or PDF)
Paperback also available at Amazon.com.
Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »