Re: jsonb concatenate operator's semantics seem questionable

From: Petr Jelinek <petr(at)2ndquadrant(dot)com>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>, Josh Berkus <josh(at)agliodbs(dot)com>, Ryan Pedela <rpedela(at)datalanche(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Peter Geoghegan <pg(at)heroku(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Ilya Ashchepkov <koctep(at)gmail(dot)com>
Subject: Re: jsonb concatenate operator's semantics seem questionable
Date: 2015-05-20 05:43:43
Message-ID: 555C1F0F.4050901@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 20/05/15 01:38, Jim Nasby wrote:
> On 5/18/15 3:15 PM, Marko Tiikkaja wrote:
>> On 2015-05-18 22:10, Josh Berkus wrote:
>>> On 05/18/2015 01:04 PM, Ryan Pedela wrote:
>>>> In the context of splitting shallow and deep merge into two
>>>> operators, I
>>>> think + is better for shallow and || better for deep. The reason for +
>>>> is because many programming languages have this behavior. If I see the
>>>> below code in language I have never used before:
>>>>
>>>> objC = objA + objB
>>>>
>>>> My default assumption is that + performs a shallow merge. Like I
>>>> said, I
>>>> would rather there just be one operator.
>>>
>>> Thank you, that helps. Anyone else?
>>
>> If everyone thinks the operators mean different things, we could just
>> not add any operators and only provide functions instead.
>
> My $0.02: I would expect || to be what I want to use to add something to
> an existing JSON document, no matter what the path of what I'm adding
> is. In other words, deep merge. I certainly wouldn't expect it to be
> shallow.
>
> If we get this wrong now, we'll be stuck with it forever. At a minimum I
> think we should use anything other than || until we can figure this out.
> That leaves || available for whichever case we decide on.
>

I am of strong opinion that concat should be shallow by default. Again
it's how jquery works by default, it's how python's dict.update works
and you can find this behavior in other languages as well when dealing
with nested hashes. It's also how json would behave if you'd just did
string concatenation (removing the outermost curly brackets) and parse
it to json afterwards.

I think this whole discussion shows primarily that it's by far not
universally agreed if concatenation of json should be shallow or deep by
default and AFAICS this is true even in javascript world so we don't
really have where to look for precedents.

Given the above I would vote to just provide the function and leave out
the || operator for now.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2015-05-20 05:50:54 Re: Minor ON CONFLICT related fixes
Previous Message Jim Nasby 2015-05-20 05:40:08 Re: Change pg_cancel_*() to ignore current backend