GIN Indexes: Extensibility

Поиск
Список
Период
Сортировка
От Anton Ananich
Тема GIN Indexes: Extensibility
Дата
Msg-id D9F2F865-AD43-4946-904C-2A160B96A81F@gmail.com
обсуждение исходный текст
Ответы Re: GIN Indexes: Extensibility  (Vick Khera <vivek@khera.org>)
Список pgsql-general
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]
 [2015] <==
 [2016] <==

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 found that there is a way to customize function `int compare(Datum a, Datum b)` (proof link: https://www.postgresql.org/docs/9.5/static/gin-extensibility.html), but I found no example which shows how to use it.

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,


В списке pgsql-general по дате отправления:

Предыдущее
От: Chris Travers
Дата:
Сообщение: Re: Uber migrated from Postgres to MySQL
Следующее
От: Marc Fournier
Дата:
Сообщение: Re: Uber migrated from Postgres to MySQL