<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jsonb &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/jsonb/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Tue, 03 Oct 2017 09:51:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>PostgreSQL 9.5: How to Concatenate and Overwrite JSON Document</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 13 Aug 2016 18:13:43 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[CONCAT]]></category>
		<category><![CDATA[data type]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[jsonb]]></category>
		<category><![CDATA[overwrite]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3443</guid>

					<description><![CDATA[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 (&#124;&#124;) which used to perform Concatenate and Overwrite of JSON Document. The requirement is something like: [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&amp;linkname=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F08%2Fpostgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator%2F&#038;title=PostgreSQL%209.5%3A%20How%20to%20Concatenate%20and%20Overwrite%20JSON%20Document" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-9-5-how-to-concatenate-and-overwrite-json-document-json-jsonb-data-type-operator/" data-a2a-title="PostgreSQL 9.5: How to Concatenate and Overwrite JSON Document"></a></p><p>The PostgreSQL JSON data type is also one of the my favorite topic.<br />
I have written multiple article on PostgreSQL JSON data type. </p>
<blockquote class="wp-embedded-content" data-secret="VwMBqIgKFg"><p><a href="https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/">PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3)</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/embed/#?secret=VwMBqIgKFg" data-secret="VwMBqIgKFg" width="600" height="338" title="&#8220;PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3)&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>PostgreSQL 9.5 introduced one new operator (||) which used to perform Concatenate and Overwrite of JSON Document.</strong></p>
<blockquote><p>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. </p></blockquote>
<blockquote><p>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. </p></blockquote>
<p><strong>Please go through this full practical demonstration:</strong></p>
<p><strong>Create a table with Sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestJSON
(
	ID INTEGER PRIMARY KEY
	,DepartName VARCHAR(250)
	,EmployeeDetails JSONB
	,Address JSONB
);

INSERT INTO tbl_TestJSON
VALUES 
(
	1
	,'Sales'
	,'
	{"employees":[
	    {"firstName":"Anvesh", "lastName":"Patel"},
	    {"firstName":"Eric", "lastName":"Marin"},
	    {"firstName":"Martin", "lastName":"Loother"}
	]}'
	,'{"address" : "Hyderabad"}'
)
,(
	2
	,'Production'
	,'
	{"employees":[
	    {"firstName":"Neevan", "lastName":"Patel"},
	    {"firstName":"Roy", "lastName":"Boon"},
	    {"firstName":"Nancy", "lastName":"Shah"}
	]}'
	,'{"address" : "Ahmedabad"}'
);</pre> </p>
<p><strong>Using (||) operator can concat two JSON String:</strong><br />
In the below example, you can see &#8220;address&#8221; key is merged with &#8220;employees&#8221; key.</p>
<pre class="crayon-plain-tag">SELECT EmployeeDetails || Address AS JsonData FROM tbl_TestJSON;
/*
		   JsonData
------------------------------------------------
{"address": "Hyderabad"
 ,"employees": 
	[{"lastName": "Patel", "firstName": "Anvesh"}
	,{"lastName": "Marin", "firstName": "Eric"}
	,{"lastName": "Loother", "firstName": "Martin"}
	]
}
{"address": "Ahmedabad"
 ,"employees": 
	[{"lastName": "Patel", "firstName": "Neevan"}
	,{"lastName": "Boon", "firstName": "Roy"}
	,{"lastName": "Shah", "firstName": "Nancy"}
	]
}*/</pre> </p>
<p><strong>Using (||) operator can overwrite the JSON string:</strong><br />
In the below example, you can see the replacement of &#8220;address&#8221; value. </p>
<pre class="crayon-plain-tag">SELECT EmployeeDetails || Address || '{"address": "Pune"}'FROM tbl_TestJSON;
/*
		  JsonData
-------------------------------------------------
{"address": "Pune"
 ,"employees": 
	    [{"lastName": "Patel", "firstName": "Anvesh"}
	    ,{"lastName": "Marin", "firstName": "Eric"}
	    ,{"lastName": "Loother", "firstName": "Martin"}
	    ]
}
{"address": "Pune"
 ,"employees": 
	   [{"lastName": "Patel", "firstName": "Neevan"}
	   ,{"lastName": "Boon", "firstName": "Roy"}
	   ,{"lastName": "Shah", "firstName": "Nancy"}
	   ]
}*/</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3)</title>
		<link>https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/</link>
					<comments>https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 14 Feb 2016 19:52:56 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[jsonb]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL 9.4]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1468</guid>

					<description><![CDATA[JSON is one of the interesting topics or new RDBMSs, now with the new version of PostgreSQL 9.4, we can store JSON formatted data. You can visit this article, on the overview of PostgreSQL 9.4 features. Now We can say, we have PostgreSQL 9.4 with the RDBMS + NOSQL concepts. We can also store JSON [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fpostgresql-9-4-the-json-data-type-is-awesome-part-1%2F&amp;linkname=PostgreSQL%209.4%3A%20The%20JSON%20data%20type%20is%20Awesome%20%28Part%201%2F3%29" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fpostgresql-9-4-the-json-data-type-is-awesome-part-1%2F&amp;linkname=PostgreSQL%209.4%3A%20The%20JSON%20data%20type%20is%20Awesome%20%28Part%201%2F3%29" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fpostgresql-9-4-the-json-data-type-is-awesome-part-1%2F&amp;linkname=PostgreSQL%209.4%3A%20The%20JSON%20data%20type%20is%20Awesome%20%28Part%201%2F3%29" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fpostgresql-9-4-the-json-data-type-is-awesome-part-1%2F&amp;linkname=PostgreSQL%209.4%3A%20The%20JSON%20data%20type%20is%20Awesome%20%28Part%201%2F3%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fpostgresql-9-4-the-json-data-type-is-awesome-part-1%2F&amp;linkname=PostgreSQL%209.4%3A%20The%20JSON%20data%20type%20is%20Awesome%20%28Part%201%2F3%29" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fpostgresql-9-4-the-json-data-type-is-awesome-part-1%2F&amp;linkname=PostgreSQL%209.4%3A%20The%20JSON%20data%20type%20is%20Awesome%20%28Part%201%2F3%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fpostgresql-9-4-the-json-data-type-is-awesome-part-1%2F&#038;title=PostgreSQL%209.4%3A%20The%20JSON%20data%20type%20is%20Awesome%20%28Part%201%2F3%29" data-a2a-url="https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/" data-a2a-title="PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3)"></a></p><p>JSON is one of the interesting topics or new RDBMSs, now with the new version of PostgreSQL 9.4, we can store JSON formatted data.</p>
<p><a href="https://www.dbrnd.com/2015/11/postgresql-new-powerful-feature-of-postgresql-9-4-2/" target="_blank"><code>You can visit this article, on the overview of PostgreSQL 9.4 features.</code></a></p>
<blockquote><p><em>Now We can say, we have PostgreSQL 9.4 with the RDBMS + NOSQL concepts. </em></p></blockquote>
<p>We can also store JSON data as text, but the JSON Data types have the advantage of enforcing each stored for validing JSON rules or formats.</p>
<p>PostgreSQL 9.4 also introduced some set of JSON specific functions and operators.</p>
<p><strong>Two type of SON data types:</strong></p>
<blockquote><p><strong>json:</strong> It stores an exact copy of the input json text, while processing functions it reparses for each execution. Our insertion process may faster by using this json data type.<br />
The JSON data type also preserves a white space between tokens and order of the keys because it stores an exact copy of json input text.</p>
<p><strong>jsonb: </strong><br />
It stores the JSON formatted data in a decomposed binary format so input slightly slower because of the conversion overhead.<br />
(While inserting, it is validating the correct format of JSON. If JSON format is invalid, you cannot insert it.)</p>
<p>The jsonb data type does not preserve white space and order of object keys.<br />
<strong>Automatically, it also removes a duplicate key from the input string and keep last value only.</strong></p></blockquote>
<p>If we do not have any problem with ordering of object key, we should use jsonb data type to store JSON formatted data.</p>
<p><strong>Below is a small practical demonstration of this:</strong></p>
<p><strong>First, create sample table with jsonb data type:</p>
<p></strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_TestJSON
(
	ID INTEGER PRIMARY KEY
	,DepartName VARCHAR(250)
	,EmployeeDetails JSONB
);</pre><p>
<p><strong>Insert correct JSON formatted data:</strong><br />
Please also test and try to insert some incorrect JSON formatted data, you will get an error like: invalid input syntax for type json.</p><pre class="crayon-plain-tag">INSERT INTO tbl_TestJSON
VALUES 
(
	1
	,'Sales'
	,'
	{"employees":[
	    {"firstName":"Anvesh", "lastName":"Patel"},
	    {"firstName":"Eric", "lastName":"Marin"},
	    {"firstName":"Martin", "lastName":"Loother"}
	]}'
)
,(
	2
	,'Production'
	,'
	{"employees":[
	    {"firstName":"Neevan", "lastName":"Patel"},
	    {"firstName":"Roy", "lastName":"Boon"},
	    {"firstName":"Nancy", "lastName":"Shah"}
	]}'
);</pre><p>
<p><strong>SELECT data by searching the key value using WHERE clause:</strong></p><pre class="crayon-plain-tag">SELECT * FROM tbl_TestJSON 
WHERE EmployeeDetails @&gt; '{"employees":[{"lastName":"Loother"}]}'</pre><p>
<p><strong>The Result: Returned only one record.</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJSONDataType.png" rel="attachment wp-att-1552"><img fetchpriority="high" decoding="async" class="alignnone wp-image-1552 size-full" title="Postgre SQL JSON Data Type" src="https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJSONDataType.png" alt="Postgre SQL JSON Data Type" width="1270" height="86" srcset="https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJSONDataType.png 1270w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJSONDataType-300x20.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJSONDataType-768x52.png 768w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJSONDataType-1024x69.png 1024w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJSONDataType-750x51.png 750w, https://www.dbrnd.com/wp-content/uploads/2016/02/PostgreSQLJSONDataType-150x10.png 150w" sizes="(max-width: 1270px) 100vw, 1270px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
