Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1faIMj-0002PJ-Ee for pgsql-general@arkaria.postgresql.org; Tue, 03 Jul 2018 10:16:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1faIMh-0002Sy-FH for pgsql-general@arkaria.postgresql.org; Tue, 03 Jul 2018 10:16:55 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1faIMg-0002Sr-W9 for pgsql-general@lists.postgresql.org; Tue, 03 Jul 2018 10:16:55 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1faIMd-00054k-RP for pgsql-general@lists.postgresql.org; Tue, 03 Jul 2018 10:16:53 +0000 Received: by mail-wm0-x22a.google.com with SMTP id l15-v6so10015932wmc.1 for ; Tue, 03 Jul 2018 03:16:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=open-lab-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1OR9fITx2MRS9efyBHpk2XGzazggKmLpbileOicv9dk=; b=YxH5TZIe453RHfoZpIVCE0hiFDq4WRfeuV6tq/0O8UbuuDgy90Hn2Oc0FVZpdajPED QOZnnHet58GB0yr7o7K9AqC3/jB1UX5Rsfg0/2XfmlaHmyPmJlBIzPGROIiNEyh0GJgU I3WS9bJL+0dDQeT3PMK2ZKWjdveS+t/bWjn5HPCw33ZHgfkiS3xpgAEkBId/X0MdtVLX 0X28bL61WzMSyeUjMI+J3S2l+7ffhHSbE1Dtxtg1RYdmI0h1L50kPViq60WS7Wf4vSxf irZtJy4ME/Oi9Y8+mZZygO4tXciNMQ926yffiEPB9dlNXGZ7lcDaIuil91U8TDV3QwjA yEGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1OR9fITx2MRS9efyBHpk2XGzazggKmLpbileOicv9dk=; b=K/TK9PNJKN7n4NgcVtA/1BRt8b1kMb+ZHza7ci/H/oZFHCAOrY0XQuXkLO7mVNiGqW eT04c9/8WcaqD7inrMM+n5zfxN4y0e4DJ5YW7iIq687zuUR+bX5B9ZrtNWyZ/CHuNBUr p9deN2fKm+uKjbM6GrpskfMTiESEFupDzLOPm+BwXIpswyHFV4aI1EXMUJrbW9/AsvNG pfOD9eXchSWwEB8X7Fa59OwIIRDzd2EfinDahkzOA2wRidXWeai7c4LRxQR2Vyc7Y62l MU/6JXgW7MbuzwWYKeXORPcUF2YozFZlNW8Uq0mhEZUCK8Z2G/AFFn6G1JppoOVQCXxK VBMg== X-Gm-Message-State: APt69E0TA336rE+bQOL13sNO6TrqZA+8EGkN5oQKVdquhuV//u++AVYF kK2gderog9zXlf2DKCBD2zxxjqhCY8I= X-Google-Smtp-Source: AAOMgpfhCrTsUoma8YOFTnVx2DOPwo6gbZlU02VnaVpxYNH84K5QTFoOg7Jgsjx8uxa5I1WIyjj7HQ== X-Received: by 2002:a1c:8010:: with SMTP id b16-v6mr11255035wmd.41.1530613009687; Tue, 03 Jul 2018 03:16:49 -0700 (PDT) Received: from [172.20.10.2] (p4FC1212B.dip0.t-ipconnect.de. [79.193.33.43]) by smtp.gmail.com with ESMTPSA id c10-v6sm1822339wrh.44.2018.07.03.03.16.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jul 2018 03:16:47 -0700 (PDT) From: "Enrico Thierbach" To: "Oleg Bartunov" Cc: "pgsql-generallists.postgresql.org" Subject: Re: Trouble matching a nested value in JSONB entries Date: Tue, 03 Jul 2018 12:16:46 +0200 X-Mailer: MailMate (1.11.2r5479) Message-ID: <82F5E247-F0E9-40BF-AA5D-C136AB4D8459@open-lab.org> In-Reply-To: References: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_MailMate_CBA2714F-BC26-4682-A680-BD10B4E5DF4C_=" Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=_MailMate_CBA2714F-BC26-4682-A680-BD10B4E5DF4C_= Content-Type: text/plain; charset=utf-8; format=flowed; markup=markdown Content-Transfer-Encoding: 8bit Oleg, >> 1 | {"group_id": 1} >> 2 | {“group_id": 1} >> 3 | {“group_id": 2} >> 4 | {“group_id": 3} >> >> PS: Please note that I am currently at postgres 9.5. An update, if >> necessary, would be possible though. > > Upgrade, please ! > > I have only master 11beta2 right now: > > select * from qq where js @> '{"group_id":1}'; > id | js > ----+----------------- > 1 | {"group_id": 1} > 2 | {"group_id": 1} > (2 rows) thanks for your answer. Your code does work fine on 9.5 already; what I would like to achieve is to get records where the group_id entry is 1 or 2, and a fear that select * from mytable where (metadata @> '{"group_id":1}') OR (metadata @> '{"group_id”:2}’) - while doable - would not make the best use of existing indices. Any more ideas? Best, /eno --=_MailMate_CBA2714F-BC26-4682-A680-BD10B4E5DF4C_= Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

Oleg,

1 | {"group_id": 1}
2 | {=E2=80=9Cgroup_id": 1}
3 | {=E2=80=9Cgroup_id": 2}
4 | {=E2=80=9Cgroup_id": 3}

PS: Please note that I am currently at postgres 9.5. An u= pdate, if
necessary, would be possible though.

Upgrade, please !

I have only master 11beta2 right now:

select * from qq where js @> '{"group_id":1}';
id | js
----+-----------------
1 | {"group_id": 1}
2 | {"group_id": 1}
(2 rows)

thanks for your answer. Your code does work fine on 9.5 a= lready; what I would like to achieve is to get records where the group_id= entry is 1 or 2, and a fear that

select * from myt=
able where (metadata @> '{"group_id":1}') OR (metadata @> '{"group_=
id=E2=80=9D:2}=E2=80=99)
  • while doable - would not make the best use of existing indices.

Any more ideas?
Best,
/eno

--=_MailMate_CBA2714F-BC26-4682-A680-BD10B4E5DF4C_=--