<?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>JSON_EACH &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/json_each/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 12:55:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>PostgreSQL 9.4: Introduced JSON Functions and Operators (Part 2/3)</title>
		<link>https://www.dbrnd.com/2016/02/postgresql-9-4-introduced-json-functions-and-operators-part-2/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 15 Feb 2016 19:23:58 +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[JSON_EACH]]></category>
		<category><![CDATA[JSON_OBJECT_KEYS]]></category>
		<category><![CDATA[jsonb_each]]></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=1559</guid>

					<description><![CDATA[In the previous post, I discussed newly introduced JSON data type of PostgreSQL 9.4. In this post, I am showing some of the basic JSON functions and operators which are also introduced by PostgreSQL 9.4. Create sample table with jsonb data type and insert sample JSON data: [crayon-6a8f4be6c6002637636664/] SELECT JSON Data using &#8216;->&#8217; and &#8216;->>&#8217; [&#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-introduced-json-functions-and-operators-part-2%2F&amp;linkname=PostgreSQL%209.4%3A%20Introduced%20JSON%20Functions%20and%20Operators%20%28Part%202%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-introduced-json-functions-and-operators-part-2%2F&amp;linkname=PostgreSQL%209.4%3A%20Introduced%20JSON%20Functions%20and%20Operators%20%28Part%202%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-introduced-json-functions-and-operators-part-2%2F&amp;linkname=PostgreSQL%209.4%3A%20Introduced%20JSON%20Functions%20and%20Operators%20%28Part%202%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-introduced-json-functions-and-operators-part-2%2F&amp;linkname=PostgreSQL%209.4%3A%20Introduced%20JSON%20Functions%20and%20Operators%20%28Part%202%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-introduced-json-functions-and-operators-part-2%2F&amp;linkname=PostgreSQL%209.4%3A%20Introduced%20JSON%20Functions%20and%20Operators%20%28Part%202%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-introduced-json-functions-and-operators-part-2%2F&amp;linkname=PostgreSQL%209.4%3A%20Introduced%20JSON%20Functions%20and%20Operators%20%28Part%202%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-introduced-json-functions-and-operators-part-2%2F&#038;title=PostgreSQL%209.4%3A%20Introduced%20JSON%20Functions%20and%20Operators%20%28Part%202%2F3%29" data-a2a-url="https://www.dbrnd.com/2016/02/postgresql-9-4-introduced-json-functions-and-operators-part-2/" data-a2a-title="PostgreSQL 9.4: Introduced JSON Functions and Operators (Part 2/3)"></a></p><p>In the previous post, I discussed newly introduced JSON data type of PostgreSQL 9.4.</p>
<p>In this post, I am showing some of the basic JSON functions and operators which are also introduced by PostgreSQL 9.4.</p>
<p><strong>Create sample table with jsonb data type and insert sample JSON data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestJSONData
(
	ID INTEGER PRIMARY KEY
	,DepartName VARCHAR(250)
	,EmployeeDetails JSONB
);

INSERT INTO tbl_TestJSONData
VALUES 
(
	1
	,'Sales'
	,'	
	{
		"firstName":"Anvesh"
		,"lastName":"Patel"
		,"gender":"Male"
		,"address":"Hyederabad"
		,"age":28
		,"role":
		[
			"admin"
			,"vendor"
		]
	}	    
	'
)
,(
	2
	,'Production'
	,'	
	{
		"firstName":"Neevan"
		,"lastName":"Patel"
		,"gender":"Male"
		,"address":"Hyederabad"
		,"age":20
		,"role":
		[
			"user"
			,"production"
		]
	}	    
	'
);</pre> </p>
<p><strong>SELECT JSON Data using &#8216;->&#8217; and &#8216;->>&#8217; operators:</strong></p>
<pre class="crayon-plain-tag">SELECT EmployeeDetails-&gt;'firstName' AS FirstName 
FROM tbl_TestJSONData;

/* Result as a JSON object. (Using ->)
firstname
----------
"Anvesh"
"Neevan"
*/</pre> </p>
<pre class="crayon-plain-tag">SELECT EmployeeDetails->>'firstName' AS FirstName 
FROM tbl_TestJSONData;

/* Result as a TEXT. (Using ->>)
firstname
----------
Anvesh
Neevan
*/</pre> </p>
<p><strong>JSON Key value criteria in WHERE clause: </strong></p>
<pre class="crayon-plain-tag">SELECT *FROM tbl_TestJSONData 
WHERE EmployeeDetails @&gt; '{"age":28}'; 

/* one sales record is returned. */</pre>
<p><strong>JSON_EACH and JSONB_EACH Functions:</strong><br />
JSON_EACH and JSONB_EACH function to expand a JSONs data and nested JSONs are not expanded.<br />
JSON_EACH for <strong>json </strong>data type and JSONB_EACH for <strong>jsonb </strong>data type.</p>
<pre class="crayon-plain-tag">SELECT jsonb_each(EmployeeDetails) AS JSONData FROM tbl_TestJSONData;

/*Result:

JSONData 
---------------
"(age,28)"
"(role,"[""admin"", ""vendor""]")"
"(gender,"""Male""")"
"(address,"""Hyederabad""")"
"(lastName,"""Patel""")"
"(firstName,"""Anvesh""")"
"(age,20)"
"(role,"[""user"", ""production""]")"
"(gender,"""Male""")"
"(address,"""Hyederabad""")"
"(lastName,"""Patel""")"
"(firstName,"""Neevan""")"

*/</pre> </p>
<p><strong>JSON_OBJECT_KEYS and JSONB_OBJECT_KEYS Functions:<br />
</strong>Returns all set of keys of JSON object and nested keys are not displayed.<br />
JSON_OBJECT_KEYS is for <strong>json</strong> data type and JSONB_OBJECT_KEYS is for <strong>jsonb </strong>data type. </p>
<pre class="crayon-plain-tag">SELECT jsonb_object_keys(EmployeeDetails) AS JSONKeys
FROM tbl_TestJSONData;

/*Result:
age
role
gender
address
lastName
firstName
age
role
gender
address
lastName
firstName

*/</pre> </p>
<p><strong>JSON_TYPEOF and JSONB_TYPEOF Functions:</strong><br />
This both functions respectively, for each data type and return the data type of the JSON keys. </p>
<pre class="crayon-plain-tag">SELECT jsonb_typeof(EmployeeDetails-&gt;'firstName') AS JSONKeyDataType
FROM tbl_TestJSONData;</pre>
<a href="http://www.postgresql.org/docs/9.4/static/functions-json.html" target="_blank"><code><strong>For more reference you can visit this official PostgreSQL document.</strong></code></a></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
