agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Anton Ananich <anton.ananich@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Custom sort order with jsonb key
Date: Thu, 23 Jun 2016 21:38:54 +0300
Message-ID: <1BFCD444-70DD-4A32-B2AB-CEFCC2922419@gmail.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
Dear colleagues,
I have a table in PostgreSQL with some data:
create table FOO (
key jsonb
);
insert into FOO(key) values ('[2014]');
insert into FOO(key) values ('[2015]');
insert into FOO(key) values ('[2016]');
insert into FOO(key) values ('[2014, 2]');
insert into FOO(key) values ('[2014, 2, 3]');
insert into FOO(key) values ('[2014, 3]');
insert into FOO(key) values ('[2014,2,4]');
insert into FOO(key) values ('[2014, 2,4]');
insert into FOO(key) values ('[2014,3,13]');
insert into FOO(key) values ('[2014, 2, 15]');
And I try to sort these rows like that:
SELECT key FROM FOO order by key;
The result is:
[2014]
[2015] <==
[2016] <==
[2014, 2]
[2014, 3] <==
[2014, 2, 3]
[2014, 2, 4]
[2014, 2, 4]
[2014, 2, 15]
[2014, 3, 13]
But what I need is
[2014]
[2014, 2]
[2014, 2, 3]
[2014, 2, 4]
[2014, 2, 4]
[2014, 2, 15]
[2014, 3] <==
[2014, 3, 13]
[2015] <==
[2016] <==
is there a way to achieve it?
Regards,
Anthony Ananich
http://ananich.pro <http://ananich.pro/;
view thread (4+ messages) latest in thread
Message-ID: <1BFCD444-70DD-4A32-B2AB-CEFCC2922419@gmail.com>
Permalink: ../1BFCD444-70DD-4A32-B2AB-CEFCC2922419@gmail.com/
Also on: postgresql.org/message-id/1BFCD444-70DD-4A32-B2AB-CEFCC2922419@gmail.com
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: anton.ananich@gmail.com
Subject: Re: Custom sort order with jsonb key
In-Reply-To: <1BFCD444-70DD-4A32-B2AB-CEFCC2922419@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox