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 1qgI8H-00F3dz-3S for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Sep 2023 05:09:45 +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 1qgI8E-00EWsY-59 for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Sep 2023 05:09:41 +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 1qgI8D-00EWsE-Og for pgsql-hackers@lists.postgresql.org; Wed, 13 Sep 2023 05:09:41 +0000 Received: from ewsoutbound.kpnmail.nl ([195.121.94.184]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgI83-004H95-Jx for pgsql-hackers@lists.postgresql.org; Wed, 13 Sep 2023 05:09:40 +0000 X-KPN-MessageId: b3c6e0e5-51f3-11ee-b452-005056994fde Received: from smtp.kpnmail.nl (unknown [10.31.155.5]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id b3c6e0e5-51f3-11ee-b452-005056994fde; Wed, 13 Sep 2023 07:09:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=xs4all01; h=content-type:from:to:subject:mime-version:date:message-id; bh=dqWllTtwVzlEQbSmmmY5MuKX48IPU0BQOcR8r5lxzK4=; b=EPvV7dLj0pFvLppOBkTAR0ft2rO2jTcDGdMnWJzWLQh3I39UIsUCJPB8KFqgiCaKV7D5qkmO51QGi vfTpkFpm0qjT2bY968XEJsNjopE0W9bffRNUvhCsjO96jffptW51ijHTmt2FBFZdqKO6+yRQuVdfuh VRzErO/+8eaLva40dJ+fvN24d1rymuOYcDZ6MuKmILQZmssuoqfM0oYk9PdJ3q6hNOJcDWTQR6JFnw p9aaDdvrI+D7q64FhuZxx+BrbR1+Bl6AKZO0Q4ASYFmWzpnvdMZ+JvNWgqR8ne+1vkOWpcwHiQxIlY BduqdksZnctTnZYJ7hD5O5EB4q/Peog== X-KPN-MID: 33|KqVS5fAgWOcCRi1V9G44QQ9WVuL6+2qVZKLtzcKbsauB1QrtKAzILA8L96G5tzY gxJ+6LvgMwp6X8RJPrtNaBJv3kRe26aheO2Ql29MYVrA= X-KPN-VerifiedSender: Yes X-CMASSUN: 33|02rHmkOMmT8eFEz2HF4dHlm5nOuSje9IV9qealOmXrW5kqnYer/Tol+LxXNUbZy Ly8TtCYOPNSNLELyHUJwIhw== X-Originating-IP: 45.83.234.25 Received: from [192.168.178.31] (unknown [45.83.234.25]) by smtp.xs4all.nl (Halon) with ESMTPSA id b347f86f-51f3-11ee-ac77-00505699b758; Wed, 13 Sep 2023 07:09:27 +0200 (CEST) Message-ID: <640942d7-c996-0562-62c9-d69a4c1f9b1e@xs4all.nl> Date: Wed, 13 Sep 2023 07:11:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: JSON Path and GIN Questions Content-Language: en-US To: Erik Wienhold , "David E. Wheeler" , pgsql-hackers@lists.postgresql.org References: <15DD78A5-B5C4-4332-ACFE-55723259C07F@justatheory.com> <133696180.303713.1694566807910@office.mailbox.org> From: Erik Rijkers In-Reply-To: <133696180.303713.1694566807910@office.mailbox.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Op 9/13/23 om 03:00 schreef Erik Wienhold: > 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.com/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=# select id from movies where movie @@ '$ ?(@.title == "New Life Rescue")'; >> id >> ---- >> (0 rows) >> >> david=# select id from movies where movie @? '$ ?(@.title == "New Life Rescue")'; >> id >> ---- >> 10 >> (1 row) >> >> I posted this question on Stack Overflow (https://stackoverflow.com/q/77046554/79202), >> and from the suggestion I got there, it seems that @@ expects a boolean to 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’d 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 return >> a boolean or not. > > +1 > > [1] https://www.postgresql.org/message-id/CACJufxE01sxgvtG4QEvRZPzs_roggsZeVvBSGpjM5tzE5hMCLA%40mail.gmail.com > > -- > Erik "All use of json*() functions preclude index usage." That sentence is missing from the documentation. Erik Rijkers