<?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>GIN INDEX &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/gin-index/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 13:01:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.5</generator>
	<item>
		<title>PostgreSQL 9.4: Indexing on jsonb Data Type (Part 3/3)</title>
		<link>https://www.dbrnd.com/2016/02/postgresql-9-4-indexing-on-jsonb-data-type-part-3/</link>
					<comments>https://www.dbrnd.com/2016/02/postgresql-9-4-indexing-on-jsonb-data-type-part-3/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 16 Feb 2016 19:40:44 +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[GIN INDEX]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JSON Datatype]]></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=1580</guid>

					<description><![CDATA[In the previous two parts, I shared basic about JSON data types, operators and functions of PostgreSQL 9.4. In this post, I am showing to create a GIN INDEX on the jsonb data type of PostgreSQL 9.4. If we are thinking to store large JSON document in PostgreSQL, we should also apply proper indexing on [&#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-indexing-on-jsonb-data-type-part-3%2F&amp;linkname=PostgreSQL%209.4%3A%20Indexing%20on%20jsonb%20Data%20Type%20%28Part%203%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-indexing-on-jsonb-data-type-part-3%2F&amp;linkname=PostgreSQL%209.4%3A%20Indexing%20on%20jsonb%20Data%20Type%20%28Part%203%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-indexing-on-jsonb-data-type-part-3%2F&amp;linkname=PostgreSQL%209.4%3A%20Indexing%20on%20jsonb%20Data%20Type%20%28Part%203%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-indexing-on-jsonb-data-type-part-3%2F&amp;linkname=PostgreSQL%209.4%3A%20Indexing%20on%20jsonb%20Data%20Type%20%28Part%203%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-indexing-on-jsonb-data-type-part-3%2F&amp;linkname=PostgreSQL%209.4%3A%20Indexing%20on%20jsonb%20Data%20Type%20%28Part%203%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-indexing-on-jsonb-data-type-part-3%2F&amp;linkname=PostgreSQL%209.4%3A%20Indexing%20on%20jsonb%20Data%20Type%20%28Part%203%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-indexing-on-jsonb-data-type-part-3%2F&#038;title=PostgreSQL%209.4%3A%20Indexing%20on%20jsonb%20Data%20Type%20%28Part%203%2F3%29" data-a2a-url="https://www.dbrnd.com/2016/02/postgresql-9-4-indexing-on-jsonb-data-type-part-3/" data-a2a-title="PostgreSQL 9.4: Indexing on jsonb Data Type (Part 3/3)"></a></p><p>In the previous two parts, I shared basic about JSON data types, operators and functions of PostgreSQL 9.4.</p>
<p>In this post, I am showing to create a GIN INDEX on the jsonb data type of PostgreSQL 9.4.</p>
<blockquote><p>If we are thinking to store large JSON document in PostgreSQL, we should also apply proper indexing on it.<br />
The GIN indexing is very useful to search key and value pairs from the large jsonb documents.<br />
The GIN index supports queries with this all @>, ?, ?&#038; and ? different operators. </p></blockquote>
<p>Below is a small demonstration on GIN index:<br />
<strong>First, create a sample table with jsonb data type and 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>Create a GIN index on jsonb column:</strong></p>
<pre class="crayon-plain-tag">CREATE INDEX idx_tbl_TestJSONData_EmployeeDetails 
ON tbl_TestJSONData USING GIN (EmployeeDetails);</pre> </p>
<p><strong>The SELECT query which makes use of this created index:</strong></p>
<pre class="crayon-plain-tag">SELECT 
	EmployeeDetails -&gt; 'firstName'
	,EmployeeDetails -&gt; 'lastName'
	,EmployeeDetails -&gt; 'gender'
FROM tbl_TestJSONData
WHERE EmployeeDetails @&gt; '{"age":28}'</pre> </p>
<p><strong>Create expression indexes for particular internal items and keys:</strong></p><pre class="crayon-plain-tag">CREATE INDEX idx_tbl_TestJSONData_EmployeeDetails_Roles 
ON tbl_TestJSONData USING GIN ((EmployeeDetails -&gt; 'role'));</pre><p> </p>
<p><strong>To SELECT internal &#8216;role&#8217; key which uses the index:</strong></p><pre class="crayon-plain-tag">SELECT 
	EmployeeDetails -&gt; 'firstName'
	,EmployeeDetails -&gt; 'lastName'
	,EmployeeDetails -&gt; 'gender'
FROM tbl_TestJSONData
WHERE EmployeeDetails -&gt; 'role' ? 'admin';</pre><p> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/02/postgresql-9-4-indexing-on-jsonb-data-type-part-3/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
