PostgreSQL 9.5: How to Concatenate and Overwrite JSON Document

The PostgreSQL JSON data type is also one of the my favorite topic.
I have written multiple article on PostgreSQL JSON data type.

PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3)

PostgreSQL 9.5 introduced one new operator (||) which used to perform Concatenate and Overwrite of JSON Document.

The requirement is something like: we have stored one JSON string or document into PostgreSQL. Now we require to add any new key or elements into that document.

It was not possible in the previous version of PostgreSQL, but now we can use (||) this operator to add or overwrite particular key into the JSON document.

Please go through this full practical demonstration:

Create a table with Sample data:

Using (||) operator can concat two JSON String:
In the below example, you can see “address” key is merged with “employees” key.

Using (||) operator can overwrite the JSON string:
In the below example, you can see the replacement of “address” value.

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from

Leave a Reply

Be the First to Comment!

Notify of