Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgEEv-00EpmB-66 for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Sep 2023 01:00:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qgEEt-00D9rb-TW for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Sep 2023 01:00:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgEEt-00D9rI-FY for pgsql-hackers@lists.postgresql.org; Wed, 13 Sep 2023 01:00:19 +0000 Received: from mout-u-107.mailbox.org ([2001:67c:2050:101:465::107]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgEEp-004F8N-Gc for pgsql-hackers@lists.postgresql.org; Wed, 13 Sep 2023 01:00:18 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4RlhvD3TXVz9sdK; Wed, 13 Sep 2023 03:00:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ewie.name; s=MBO0001; t=1694566808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5yvL6Vzb8QdHwoHMx+w1MUEQ1X2Tt82CTRn/ytbMqvQ=; b=Q9H9Gc7qj04dfOaX1MQq63qgtng/iYD/2NQD9RXBF9Bhy8ZtIpXfE1DjdOPy+7oYRWvpNs QZp/q44dT8/9fa1YCEF/iOfAj24yFATwehbdu3qtFpJ3XpI9ezItZ25lhqGNBuvj3zlejp niQSH20RHvR0SHXH26yj1hVQir2Bx5hI83LJRr5zVTlXg1YKkedRKSTsZ6CkuS5+OQRg5x xe73RDfrFPDQ0OTVCg8zMdBKfTYriGhFJ0+Dh8ON5QvJAgXkVu2zBNHDYg513aurZKvP36 XRsLFPUwFw1KUBsCg4spVbIxAb10lg1GcRn33ZP5XIKyre7mDFn5dcHmNXCYpA== Date: Wed, 13 Sep 2023 03:00:07 +0200 (CEST) From: Erik Wienhold To: "David E. Wheeler" , pgsql-hackers@lists.postgresql.org Message-ID: <133696180.303713.1694566807910@office.mailbox.org> In-Reply-To: <15DD78A5-B5C4-4332-ACFE-55723259C07F@justatheory.com> References: <15DD78A5-B5C4-4332-ACFE-55723259C07F@justatheory.com> Subject: Re: JSON Path and GIN Questions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Normal X-Rspamd-Queue-Id: 4RlhvD3TXVz9sdK List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi David, On 13/09/2023 02:16 CEST David E. Wheeler wrote: > CREATE TABLE MOVIES (id SERIAL PRIMARY KEY, movie JSONB NOT NULL); > \copy movies(movie) from PROGRAM 'curl -s https://raw.githubusercontent.c= om/prust/wikipedia-movie-data/master/movies.json | jq -c ".[]" | sed "s|\\\= \|\\\\\\\\|g"'; > create index on movies using gin (movie); > analyze movies; > > I have been confused as to the difference between @@ vs @?: Why do these > return different results? > > david=3D# select id from movies where movie @@ '$ ?(@.title =3D=3D "New L= ife Rescue")'; > id > ---- > (0 rows) > > david=3D# select id from movies where movie @? '$ ?(@.title =3D=3D "New L= ife Rescue")'; > id > ---- > 10 > (1 row) > > I posted this question on Stack Overflow (https://stackoverflow.com/q/770= 46554/79202), > and from the suggestion I got there, it seems that @@ expects a boolean t= o be > returned by the path query, while @? wraps it in an implicit exists(). Is= that > right? That's also my understanding. We had a discussion about the docs on @@, @?= , and jsonb_path_query on -general a while back [1]. Maybe it's useful also. > If so, I=E2=80=99d like to submit a patch to the docs talking about this,= and > suggesting the use of jsonb_path_query() to test paths to see if they ret= urn > a boolean or not. +1 [1] https://www.postgresql.org/message-id/CACJufxE01sxgvtG4QEvRZPzs_roggsZe= VvBSGpjM5tzE5hMCLA%40mail.gmail.com -- Erik