Dear All,
Here is what I have:
user=# create table FOO (key jsonb);
CREATE TABLE
user=# insert into FOO(key) values ('[2014]'), ('[2015]'), ('[2016]'), ('[2014, 2]'), ('[2014, 2, 3]'), ('[2014, 3]'), ('[2014,2,4]'), ('[2014, 2,4]'), ('[2014,3,13]'), ('[2014, 2, 15]');
INSERT 0 10
user=# SELECT key FROM FOO order by key;
key
---------------
[2014]
[2015] <==
[2016] <==
[2014, 2]
[2014, 3] <==
[2014, 2, 3]
[2014, 2, 4]
[2014, 2, 4]
[2014, 2, 15]
[2014, 3, 13]
(10 rows)
In my situation this order is invalid. Obviously, year 2016 should go after 2014, like that:
key
---------------
[2014]
[2014, 2]
[2014, 2, 3]
[2014, 2, 4]
[2014, 2, 4]
[2014, 2, 15]
[2014, 3] <==
[2014, 3, 13]
This is a simplified example, my real application is much more complicated and sorted arrays could have tens of values, could even be arrays of arrays.For this reason I need to customize sort function.
I’d appreciate any information which could help me to achieve the described result, even if it is just a link to an existing example.
Regards,