-
-
Save jemminger/dc72e91a50a4ec9981778ea2e0b3100e to your computer and use it in GitHub Desktop.
PostgreSQL natural sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//sql | |
create or replace function naturalsort(text) | |
returns bytea language sql immutable strict as | |
$f$ select string_agg(convert_to(coalesce(r[2],length(length(r[1])::text) || length(r[1])::text || r[1]),'SQL_ASCII'),'\x00') | |
from regexp_matches($1, '0*([0-9]+)|([^0-9]+)', 'g') r; $f$; | |
//author: github.com/RhodiumToad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment