Re: JSON Path and GIN Questions

2023-12-17 Thread David E. Wheeler
On Dec 17, 2023, at 16:08, Tom Lane wrote: > I'd waited because the discussion was still active, and then it > kind of slipped off the radar. I'll take another look and push > some form of what I suggested. Right on. > That doesn't really address the > jsonpath oddities you were on about,

Re: JSON Path and GIN Questions

2023-12-17 Thread Tom Lane
"David E. Wheeler" writes: > Hey Tom, are you still thinking about adding this bit to the docs? I took a > quick look at master and didn’t see it there. I'd waited because the discussion was still active, and then it kind of slipped off the radar. I'll take another look and push some form of

Re: JSON Path and GIN Questions

2023-12-17 Thread David E. Wheeler
On Sep 17, 2023, at 18:09, David E. Wheeler wrote: > I think this is useful, but also that it’s worth calling out explicitly that > functions do not count as indexable operators. True by definition, of course, > but I at least had assumed that since an operator is, in a sense, syntax > sugar

Re: JSON Path and GIN Questions

2023-10-14 Thread David E. Wheeler
Thanks for the reply, Erik. Have appreciated collaborating with you on a few different things lately! > On Oct 13, 2023, at 22:50, Erik Wienhold wrote: >> Hi, finally getting back to this, still fiddling to figure out the >> differences. From the thread you reference [1], is the point that @@

Re: JSON Path and GIN Questions

2023-10-13 Thread Erik Wienhold
On 2023-10-09 01:13 +0200, David E. Wheeler write: > On Sep 12, 2023, at 21:00, Erik Wienhold wrote: > > >> 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 > >>

Re: JSON Path and GIN Questions

2023-10-08 Thread David E. Wheeler
On Sep 12, 2023, at 21:00, Erik Wienhold wrote: >> 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().

Re: JSON Path and GIN Questions

2023-09-17 Thread David E. Wheeler
On Sep 17, 2023, at 12:20, Tom Lane wrote: > After thinking about it for awhile, I think we need some more > discursive explanation of what's allowed, perhaps along the lines > of the attached. (I still can't shake the feeling that this is > duplicative; but I can't find anything comparable

Re: JSON Path and GIN Questions

2023-09-17 Thread Tom Lane
"David E. Wheeler" writes: > On Sep 15, 2023, at 20:36, Tom Lane wrote: >> I think that that indicates that you're putting the info in the >> wrong place. Perhaps the right answer is to insert something >> more explicit in section 11.2, which is the first place where >> we really spend any

Re: JSON Path and GIN Questions

2023-09-16 Thread David E. Wheeler
On Sep 16, 2023, at 18:13, Erik Wienhold wrote: > Looks like the effect of lax mode which may unwrap arrays when necessary [1]. > The array unwrapping looks like the result of jsonb_array_elements(). > > It kinda works in strict mode: > > SELECT jsonb_path_query(:'json', 'strict

Re: JSON Path and GIN Questions

2023-09-16 Thread Erik Wienhold
On 16/09/2023 22:26 CEST David E. Wheeler wrote: > I’ve started work on this; there’s so much to learn! Here’s a new example > that surprised me a bit. Using the GPS tracker example from the docs [1] > loaded into a `:json` psql variable, this output of this query makes perfect > sense to me: >

Re: JSON Path and GIN Questions

2023-09-16 Thread David E. Wheeler
On Sep 16, 2023, at 16:50, Erik Wienhold wrote: > "For these operators, a GIN index extracts clauses of the form > **accessors_chain = constant** out of the jsonpath pattern, and does the > index search based on the keys and values mentioned in these clauses." > > I don't know if this is a

Re: JSON Path and GIN Questions

2023-09-16 Thread Erik Wienhold
On 16/09/2023 22:19 CEST David E. Wheeler wrote: > On Sep 15, 2023, at 23:59, Erik Rijkers wrote: > > > movie @? '$ ?($.year >= 2023)' > > > > I believe it is indeed not possible to have such a unequality-search use > > the GIN index. It is another weakness of JSON that can be unexpected to >

Re: JSON Path and GIN Questions

2023-09-16 Thread David E. Wheeler
On Sep 12, 2023, at 21:00, Erik Wienhold wrote: >> 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 I’ve started work on this; there’s so much to learn! Here’s a new

Re: JSON Path and GIN Questions

2023-09-16 Thread David E. Wheeler
On Sep 15, 2023, at 23:59, Erik Rijkers wrote: > movie @? '$ ?($.year >= 2023)' > > I believe it is indeed not possible to have such a unequality-search use the > GIN index. It is another weakness of JSON that can be unexpected to those > not in the fullness of Knowledge of the manual. Yes,

Re: JSON Path and GIN Questions

2023-09-16 Thread David E. Wheeler
On Sep 15, 2023, at 20:36, Tom Lane wrote: > I think that that indicates that you're putting the info in the > wrong place. Perhaps the right answer is to insert something > more explicit in section 11.2, which is the first place where > we really spend any effort discussing what can be

Re: JSON Path and GIN Questions

2023-09-15 Thread Erik Rijkers
Op 9/15/23 om 22:27 schreef David E. Wheeler: On Sep 12, 2023, at 21:00, Erik Wienhold wrote: 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. Okay, I’ll take a pass at expanding the docs

Re: JSON Path and GIN Questions

2023-09-15 Thread Tom Lane
"David E. Wheeler" writes: > On Sep 14, 2023, at 00:41, Tom Lane wrote: >> As far as json in particular is concerned, 8.14.4 jsonb Indexing [4] >> is pretty clear about what is or is not supported. > How do you feel about this note, then? I think it's unnecessary. If we did consider it

Re: JSON Path and GIN Questions

2023-09-15 Thread David E. Wheeler
On Sep 12, 2023, at 21:00, Erik Wienhold wrote: > 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. Okay, I’ll take a pass at expanding the docs on this. I think a little mini-tutorial

Re: JSON Path and GIN Questions

2023-09-15 Thread David E. Wheeler
On Sep 14, 2023, at 00:41, Tom Lane wrote: > As far as json in particular is concerned, 8.14.4 jsonb Indexing [4] > is pretty clear about what is or is not supported. How do you feel about this note, then? diff --git a/doc/src/sgml/json.sgml b/doc/src/sgml/json.sgml index

Re: JSON Path and GIN Questions

2023-09-13 Thread Tom Lane
Erik Rijkers writes: > p 9/13/23 om 22:01 schreef David E. Wheeler: >> On Sep 13, 2023, at 01:11, Erik Rijkers wrote: >>> "All use of json*() functions preclude index usage." >> Where did that come from? Why wouldn’t JSON* functions use indexes? I see >> that the docs only mention operators;

Re: JSON Path and GIN Questions

2023-09-13 Thread Erik Rijkers
p 9/13/23 om 22:01 schreef David E. Wheeler: On Sep 13, 2023, at 01:11, Erik Rijkers wrote: "All use of json*() functions preclude index usage." That sentence is missing from the documentation. Where did that come from? Why wouldn’t JSON* functions use indexes? I see that the docs only

Re: JSON Path and GIN Questions

2023-09-13 Thread David E. Wheeler
On Sep 13, 2023, at 01:11, Erik Rijkers wrote: > "All use of json*() functions preclude index usage." > > That sentence is missing from the documentation. Where did that come from? Why wouldn’t JSON* functions use indexes? I see that the docs only mention operators; why would the

Re: JSON Path and GIN Questions

2023-09-12 Thread Erik Rijkers
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

Re: JSON Path and GIN Questions

2023-09-12 Thread 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

JSON Path and GIN Questions

2023-09-12 Thread David E. Wheeler
Greetings Hackers, Been a while! I’m working on some experiments with JSONB columns and GIN indexes, and have operated on the assumption that JSON Path operations would take advantage of GIN indexes, with json_path_ops as a nice optimization. But I’ve run into what appear to be some