jsonb nested values and indexes

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: jsonb nested values and indexes
Date: 2014-05-20 20:23:53
Message-ID: CAFj8pRARjJ2f8ta4VqNZDAv8gyVLXEUcmzyc317Kz8=eTU-TuQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

I don't know a doc about jsonb indexes

"But in jsonb_path_ops, each index item is a hash of both the value and the
key(s) leading to it; for example to index {"foo": {"bar": "baz"}}, a
single index item would be created incorporating all three of foo, bar, and
baz into the hash value. Thus a containment query looking for this
structure would result in an extremely specific index search; but there is
no way at all to find out whether foo appears as a key. On the other hand,
a jsonb_ops index would create three index items representing foo, bar, and
baz separately;"

What keys I can search on this jsonb?

postgres=# create table x(a jsonb);
CREATE TABLE
postgres=# insert into x values('{"foo": {"bar": "baz"}}');
INSERT 0 1

postgres=# select * from x where a ? 'foo';
a
-------------------------
{"foo": {"bar": "baz"}}
(1 row)

postgres=# select * from x where a ? 'bar';
a
---
(0 rows)

postgres=# select * from x where a ? 'baz';
a
---
(0 rows)

???

Regards

Pavel

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2014-05-20 20:39:16 jsonb inequality operators
Previous Message Bruce Momjian 2014-05-20 20:22:23 Re: pg_upgrade fails: Mismatch of relation OID in database 8.4 -> 9.3