Re: jsonb concatenate operator's semantics seem questionable - Mailing list pgsql-hackers

From Oskari Saarenmaa
Subject Re: jsonb concatenate operator's semantics seem questionable
Date
Msg-id 5559D38A.2070307@ohmu.fi
Whole thread Raw
In response to Re: jsonb concatenate operator's semantics seem questionable  (Josh Berkus <josh@agliodbs.com>)
List pgsql-hackers
18.05.2015, 06:41, Josh Berkus kirjoitti:
> On 05/17/2015 05:46 PM, Robert Haas wrote:
>> On May 17, 2015, at 8:38 PM, Peter Geoghegan <pg@heroku.com> wrote:
>>> The current behavior does not seem acceptable for the concatenate
>>> operator ("operator || jsonb").
>>
>> I don't agree.  It seems pretty clear to me after reading the new posts that the behavior is not an oversight, and
that'senough for me to say that we should leave this alone. 
 
> 
> Is there a particular reason why "+" makes more sense as "shallow
> concatination" and "||" makes more sense as "deep concatination"?  Like,
> something in JS or other client languages which would make that
> preference make more sense to users?
> 
> While I hate last-minute changes in general, once we have this
> functionality as || we won't be able to swap operators later if we
> decide that deep concatination should have been ||.  So I want to be
> clear on why users will prefer that to + .

Both operations (shallow and deep merge) are useful and needed in many
applications but I've found the shallow merge to be more useful in the
"generic" use case; the deep merge implementations I've run across are
usually application specific as you need to decide what to do with
arrays, conflicting keys, etc.

I think concatenation is the right operator for shallow merge, it's
basically what would happen if you concatenated text representations of
two json objects and replaced the closing and opening braces between
them with a comma:

(substring(a::text, 1, length(a::text)-1) || ',' || substring(b::text,
2))::jsonb

Deep merge could be a function with flags to say what to do about
conflicts, etc.

/ Oskari



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Support for N synchronous standby servers - take 2
Next
From: Andrew Dunstan
Date:
Subject: Re: jsonb concatenate operator's semantics seem questionable