Re: [HACKERS] [PATCH] Generic type subscripting

From: "Dian M Fay" <dian(dot)m(dot)fay(at)gmail(dot)com>
To: "Dmitry Dolgov" <9erthalion6(at)gmail(dot)com>
Cc: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Andres Freund" <andres(at)anarazel(dot)de>, "Alexander Korotkov" <aekorotkov(at)gmail(dot)com>, "Justin Pryzby" <pryzby(at)telsasoft(dot)com>, "David Steele" <david(at)pgmasters(dot)net>, "Nikita Glukhov" <n(dot)gluhov(at)postgrespro(dot)ru>, "Alvaro Herrera" <alvherre(at)2ndquadrant(dot)com>, "David Fetter" <david(at)fetter(dot)org>, "Thomas Munro" <thomas(dot)munro(at)gmail(dot)com>, "Oleksandr Shulgin" <oleksandr(dot)shulgin(at)zalando(dot)de>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Michael Paquier" <michael(dot)paquier(at)gmail(dot)com>, "Oleg Bartunov" <obartunov(at)gmail(dot)com>, "Peter Eisentraut" <peter(dot)eisentraut(at)2ndquadrant(dot)com>, "PostgreSQL Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] [PATCH] Generic type subscripting
Date: 2021-01-21 04:37:32
Message-ID: C8OK3JQNE1KN.2H0O0RCBD576E@lamia
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed Jan 20, 2021 at 2:08 PM EST, Dmitry Dolgov wrote:
> > On Wed, Jan 20, 2021 at 11:34:16AM -0500, Dian M Fay wrote:
> > > Thanks, I need to remember to not skipp doc building for testing process
> > > even for such small changes. Hope now I didn't forget anything.
> > >
> > > > On Wed, Jan 20, 2021 at 09:58:43AM -0500, Dian M Fay wrote:
> > >
> > > > Here's a full editing pass on the documentation, with v45 and Pavel's
> > > > doc-whitespaces-fix.patch applied. I also corrected a typo in one of the
> > > > added hints.
> > >
> > > Great! I've applied almost all of it, except:
> > >
> > > + A <type>jsonb</type> value will accept assignments to nonexistent
> > > subscript
> > > + paths as long as the nonexistent elements being traversed are all
> > > arrays.
> > >
> > > Maybe I've misunderstood the intention, but there is no requirement
> > > about arrays for creating such an empty path. I've formulated it as:
> > >
> > > + A <type>jsonb</type> value will accept assignments to nonexistent
> > > subscript
> > > + paths as long as the last existing path key is an object or an array.
> >
> > My intention there was to highlight the difference between:
> >
> > * SET obj['a']['b']['c'] = '"newvalue"'
> > * SET arr[0][0][3] = '"newvalue"'
> >
> > obj has to conform to {"a": {"b": {...}}} in order to receive the
> > assignment of the nested c. If it doesn't, that's the error case we
> > discussed earlier. But arr can be null, [], and so on, and any missing
> > structure [[[null, null, null, "newvalue"]]] will be created.
>
> If arr is 'null', or any other scalar value, such subscripting will work
> only one level deep because they represented internally as an array of
> one element. If arr is '[]' the path will comply by definition. So it's
> essentially the same as for objects with no particular difference. If
> such a quirk about scalars being treated like arrays is bothering, we
> could also bend it in this case as well (see the attached version).

I missed that distinction in the original UPDATE paragraph too. Here's
another revision based on v48.

Attachment Content-Type Size
0001-more-jsonb-subscripting-documentation-edits.patch text/plain 4.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Nancarrow 2021-01-21 04:59:16 Re: Parallel INSERT (INTO ... SELECT ...)
Previous Message Fujii Masao 2021-01-21 04:36:46 Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit