From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Johann Spies <johann.spies@gmail.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: How to build a btree index with integer values on jsonb data?
Date: Thu, 06 Dec 2018 18:27:45 +0100
Message-ID: <750facc26efc79b1e44836ea1c3d985a9577f80a.camel@cybertec.at> (raw)
In-Reply-To: <CAGZ55DSm4kGiBSJaPtTk6L7hp6xDFKaKThDLmXd_4cCFFFJe5Q@mail.gmail.com>
References: <CAGZ55DSm4kGiBSJaPtTk6L7hp6xDFKaKThDLmXd_4cCFFFJe5Q@mail.gmail.com>
Johann Spies wrote:
> How can I transform the following definition to index pubyear as
> integer and not text?
>
> CREATE INDEX pubyear_idx
> ON some_table_where_data_field_is_of_type_jsonb USING btree
> ((((((data -> 'REC'::text) -> 'static_data'::text) ->
> 'summary'::text) -> 'pub_info'::text) ->> '@pubyear'::text) COLLATE
> pg_catalog."default");
>
> While I can cast the value in a SELECT statement to integer I have
> been able to do the same while creating the index.
Replace
COLLATE pg_catalog."default"
with
::integer
> Why btree index? I want to do queries like
>
> select stuff from sometable where pubyear between 2015 and 2018;
Because b-tree indexes are perfect for >= and <=.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: laurenz.albe@cybertec.at, johann.spies@gmail.com
Subject: Re: How to build a btree index with integer values on jsonb data?
In-Reply-To: <750facc26efc79b1e44836ea1c3d985a9577f80a.camel@cybertec.at>
References: <CAGZ55DSm4kGiBSJaPtTk6L7hp6xDFKaKThDLmXd_4cCFFFJe5Q@mail.gmail.com> <750facc26efc79b1e44836ea1c3d985a9577f80a.camel@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox