<?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>PostgreSQL 9.4 &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/postgresql-9-4/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>Thu, 16 Nov 2017 13:13:55 +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: Different options to check If Table Exists in Database</title>
		<link>https://www.dbrnd.com/2017/07/postgresql-different-options-to-check-if-table-exists-in-database-to_regclass/</link>
					<comments>https://www.dbrnd.com/2017/07/postgresql-different-options-to-check-if-table-exists-in-database-to_regclass/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 12 Jul 2017 16:16:02 +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[pg_catalog]]></category>
		<category><![CDATA[pg_tables]]></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 Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[to_regclass]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5596</guid>

					<description><![CDATA[In this post, I am sharing the different options to check weather your table exists in your database or not. For checking the existence of table is a ubiquitous requirement for PostgreSQL Database Developer. PostgreSQL 9.4 introduced to_regclass to check object presence very efficiently. You can check other below options as well. Use to_regclass (From [&#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%2F2017%2F07%2Fpostgresql-different-options-to-check-if-table-exists-in-database-to_regclass%2F&amp;linkname=PostgreSQL%3A%20Different%20options%20to%20check%20If%20Table%20Exists%20in%20Database" 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%2F2017%2F07%2Fpostgresql-different-options-to-check-if-table-exists-in-database-to_regclass%2F&amp;linkname=PostgreSQL%3A%20Different%20options%20to%20check%20If%20Table%20Exists%20in%20Database" 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%2F2017%2F07%2Fpostgresql-different-options-to-check-if-table-exists-in-database-to_regclass%2F&amp;linkname=PostgreSQL%3A%20Different%20options%20to%20check%20If%20Table%20Exists%20in%20Database" 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%2F2017%2F07%2Fpostgresql-different-options-to-check-if-table-exists-in-database-to_regclass%2F&amp;linkname=PostgreSQL%3A%20Different%20options%20to%20check%20If%20Table%20Exists%20in%20Database" 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%2F2017%2F07%2Fpostgresql-different-options-to-check-if-table-exists-in-database-to_regclass%2F&amp;linkname=PostgreSQL%3A%20Different%20options%20to%20check%20If%20Table%20Exists%20in%20Database" 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%2F2017%2F07%2Fpostgresql-different-options-to-check-if-table-exists-in-database-to_regclass%2F&amp;linkname=PostgreSQL%3A%20Different%20options%20to%20check%20If%20Table%20Exists%20in%20Database" 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%2F2017%2F07%2Fpostgresql-different-options-to-check-if-table-exists-in-database-to_regclass%2F&#038;title=PostgreSQL%3A%20Different%20options%20to%20check%20If%20Table%20Exists%20in%20Database" data-a2a-url="https://www.dbrnd.com/2017/07/postgresql-different-options-to-check-if-table-exists-in-database-to_regclass/" data-a2a-title="PostgreSQL: Different options to check If Table Exists in Database"></a></p><p>In this post, I am sharing the different options to check weather your table exists in your database or not.</p>
<blockquote><p>For checking the existence of table is a ubiquitous requirement for PostgreSQL Database Developer.<br />
PostgreSQL 9.4 introduced to_regclass to check object presence very efficiently. </p></blockquote>
<p>You can check other below options as well. </p>
<p><strong>Use to_regclass (From PostgreSQL 9.4): This is the fastest option.</strong></p>
<pre class="crayon-plain-tag">SELECT to_regclass('schema_name.table_name');</pre> </p>
<p><strong>Use information_schema.tables:</strong></p>
<pre class="crayon-plain-tag">SELECT EXISTS 
(
	SELECT 1
	FROM information_schema.tables 
	WHERE table_schema = 'schema_name'
	AND table_name = 'table_name'
);</pre> </p>
<p><strong>Use catalogs tables:</strong></p>
<pre class="crayon-plain-tag">SELECT EXISTS 
(
	SELECT 1 
	FROM pg_catalog.pg_class c
	JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
	WHERE n.nspname = 'schema_name'
	AND c.relname = 'table_name'
	AND c.relkind = 'r' -- r = tables 
);</pre> </p>
<p><strong>Use pg_tables catalog:</strong></p>
<pre class="crayon-plain-tag">SELECT EXISTS 
(
	SELECT 1 
	FROM pg_tables
	WHERE schemaname = 'schema_name'
	AND tablename = 'table_name'
);</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/07/postgresql-different-options-to-check-if-table-exists-in-database-to_regclass/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL 9.4: UNNEST() WITH ORDINALITY to generate String Array Sequence Number</title>
		<link>https://www.dbrnd.com/2016/11/postgresql-9-4-unnest-with-ordinality-to-generate-string-array-sequence-number/</link>
					<comments>https://www.dbrnd.com/2016/11/postgresql-9-4-unnest-with-ordinality-to-generate-string-array-sequence-number/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 25 Nov 2016 15:35:32 +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[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>
		<category><![CDATA[sequence number]]></category>
		<category><![CDATA[string array]]></category>
		<category><![CDATA[unnest]]></category>
		<category><![CDATA[with ordinality]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3923</guid>

					<description><![CDATA[PostgreSQL 9.4 introduced WITH ORDINALITY for generating a sequence number for each element which are produced by UNNEST(). When we are talking about the string array, internal element numbering is also important for further operation. I have prepared a small demonstration of this, you can access here. Create a table with sample data: [crayon-6aa2bd63ada53185417944/] UNNEST() [&#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%2F11%2Fpostgresql-9-4-unnest-with-ordinality-to-generate-string-array-sequence-number%2F&amp;linkname=PostgreSQL%209.4%3A%20UNNEST%28%29%20WITH%20ORDINALITY%20to%20generate%20String%20Array%20Sequence%20Number" 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%2F11%2Fpostgresql-9-4-unnest-with-ordinality-to-generate-string-array-sequence-number%2F&amp;linkname=PostgreSQL%209.4%3A%20UNNEST%28%29%20WITH%20ORDINALITY%20to%20generate%20String%20Array%20Sequence%20Number" 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%2F11%2Fpostgresql-9-4-unnest-with-ordinality-to-generate-string-array-sequence-number%2F&amp;linkname=PostgreSQL%209.4%3A%20UNNEST%28%29%20WITH%20ORDINALITY%20to%20generate%20String%20Array%20Sequence%20Number" 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%2F11%2Fpostgresql-9-4-unnest-with-ordinality-to-generate-string-array-sequence-number%2F&amp;linkname=PostgreSQL%209.4%3A%20UNNEST%28%29%20WITH%20ORDINALITY%20to%20generate%20String%20Array%20Sequence%20Number" 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%2F11%2Fpostgresql-9-4-unnest-with-ordinality-to-generate-string-array-sequence-number%2F&amp;linkname=PostgreSQL%209.4%3A%20UNNEST%28%29%20WITH%20ORDINALITY%20to%20generate%20String%20Array%20Sequence%20Number" 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%2F11%2Fpostgresql-9-4-unnest-with-ordinality-to-generate-string-array-sequence-number%2F&amp;linkname=PostgreSQL%209.4%3A%20UNNEST%28%29%20WITH%20ORDINALITY%20to%20generate%20String%20Array%20Sequence%20Number" 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%2F11%2Fpostgresql-9-4-unnest-with-ordinality-to-generate-string-array-sequence-number%2F&#038;title=PostgreSQL%209.4%3A%20UNNEST%28%29%20WITH%20ORDINALITY%20to%20generate%20String%20Array%20Sequence%20Number" data-a2a-url="https://www.dbrnd.com/2016/11/postgresql-9-4-unnest-with-ordinality-to-generate-string-array-sequence-number/" data-a2a-title="PostgreSQL 9.4: UNNEST() WITH ORDINALITY to generate String Array Sequence Number"></a></p><p>PostgreSQL 9.4 introduced WITH ORDINALITY for generating a sequence number for each element which are produced by UNNEST(). </p>
<p>When we are talking about the string array, internal element numbering is also important for further operation. </p>
<p>I have prepared a small demonstration of this, you can access here.</p>
<p><strong>Create a table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TextArray(key varchar(100), tags text[]);

INSERT INTO tbl_TextArray(key, tags)
VALUES 
('first', '{aa,fe,gr,fh}'::text[]),
('sec', '{tr,we,et,ui,er}'::text[]),
('third', '{we,gh,fv,dc,sx}'::text[]);</pre> </p>
<p><strong>UNNEST() WITH ORDINALITY:</strong></p>
<pre class="crayon-plain-tag">SELECT key, ArrayOrder, tag
FROM tbl_TextArray, unnest(tags) 
WITH ORDINALITY As T (tag, ArrayOrder);</pre> </p>
<p><strong>The Result:</strong></p>
<pre class="crayon-plain-tag">dbrnd=# SELECT key, ArrayOrder, tag
dbrnd-# FROM tbl_TextArray, unnest(tags)
dbrnd-# WITH ORDINALITY As T (tag, ArrayOrder);
  key  | arrayorder | tag
-------+------------+-----
 first |          1 | aa
 first |          2 | fe
 first |          3 | gr
 first |          4 | fh
 sec   |          1 | tr
 sec   |          2 | we
 sec   |          3 | et
 sec   |          4 | ui
 sec   |          5 | er
 third |          1 | we
 third |          2 | gh
 third |          3 | fv
 third |          4 | dc
 third |          5 | sx
(14 rows)</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/11/postgresql-9-4-unnest-with-ordinality-to-generate-string-array-sequence-number/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL 9.4: How to Convert JSON ARRAY Elements into String ARRAY</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-9-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 28 Aug 2016 17:45:59 +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 array]]></category>
		<category><![CDATA[jsonb_array_elements]]></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>
		<category><![CDATA[string array]]></category>
		<category><![CDATA[string_agg]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3508</guid>

					<description><![CDATA[I have already written a couple of articles about the PostgreSQL JSON Data type and its different type of operations. PostgreSQL 9.4: The JSON data type is Awesome (Part 1/3) PostgreSQL: How to convert Table Data into JSON formatted Data? In this post, I am going to share one more demonstration about PostgreSQL JSON. In [&#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-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" 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-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" 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-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" 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-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" 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-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" 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-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&amp;linkname=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" 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-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg%2F&#038;title=PostgreSQL%209.4%3A%20How%20to%20Convert%20JSON%20ARRAY%20Elements%20into%20String%20ARRAY" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-9-4-how-to-convert-json-array-elements-into-string-array-jsonb_array_elements-string_agg/" data-a2a-title="PostgreSQL 9.4: How to Convert JSON ARRAY Elements into String ARRAY"></a></p><p>I have already written a couple of articles about the PostgreSQL JSON Data type and its different type of operations. </p>
<blockquote class="wp-embedded-content" data-secret="yHkJmiNw3k"><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=yHkJmiNw3k" data-secret="yHkJmiNw3k" 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>
<blockquote class="wp-embedded-content" data-secret="VD7ESsiJeP"><p><a href="https://www.dbrnd.com/2016/08/postgresql-how-to-convert-table-data-record-into-json-formatted-document-data/">PostgreSQL: How to convert Table Data into JSON formatted Data?</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/08/postgresql-how-to-convert-table-data-record-into-json-formatted-document-data/embed/#?secret=VD7ESsiJeP" data-secret="VD7ESsiJeP" width="600" height="338" title="&#8220;PostgreSQL: How to convert Table Data into JSON formatted Data?&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>In this post, I am going to share one more demonstration about PostgreSQL JSON. </p>
<blockquote><p>
In our system, I have stored communication message information in the form of JSON. This JSON column contains lots of different types of elements.<br />
Now one of module required to fetch this JSON array elements into a form of STRING Array only. (Something like comma separated).</p></blockquote>
<blockquote><p>We have different type of JSON functions and operator so I have achieved this solution using jsonb_array_elements.</p></blockquote>
<p><strong>Below is a full demonstration of this:</strong></p>
<p><strong>Create one table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestJsonArray
(
	ID INT
	,JsonData JSONB
);

INSERT INTO tbl_TestJsonArray
VALUES (1,'{"Name": ["Anvesh","Roy","Jenny","Neevan"]}');</pre> </p>
<p><strong>SQL Query to convert JSON elements into String Array: </strong></p>
<pre class="crayon-plain-tag">SELECT 
	ID
	,(
		SELECT string_agg(trim(JsonString::text, '"'), ', ')
		FROM jsonb_array_elements(JsonData-&gt;'Name') JsonString
	) AS StringArray
FROM   tbl_TestJsonArray;</pre>
<strong>The Result:</strong></p>
<pre class="crayon-plain-tag">id  |       StringArray
----------------------------------
   1   | Anvesh, Roy, Jenny, Neevan</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL 9.4: Using FILTER CLAUSE, multiple COUNT(*) in one SELECT Query for Different Groups</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation/</link>
					<comments>https://www.dbrnd.com/2016/08/postgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 11 Aug 2016 19:54:33 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Aggregate Function]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[FILTER CLAUSE]]></category>
		<category><![CDATA[FILTER GROUP BY]]></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=3495</guid>

					<description><![CDATA[PostgreSQL 9.4 has introduced one of the very good FILTER CLAUSE which is used to apply filters in aggregate functions. Using FILTER, You can use different types of aggregate functions without applying any GROUP BY CLAUSE. Now Imagine, that I have one Student table and I want total number of Students based different grades. What [&#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-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" 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-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" 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-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" 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-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" 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-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" 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-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&amp;linkname=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" 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-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation%2F&#038;title=PostgreSQL%209.4%3A%20Using%20FILTER%20CLAUSE%2C%20multiple%20COUNT%28%2A%29%20in%20one%20SELECT%20Query%20for%20Different%20Groups" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation/" data-a2a-title="PostgreSQL 9.4: Using FILTER CLAUSE, multiple COUNT(*) in one SELECT Query for Different Groups"></a></p><p>PostgreSQL 9.4 has introduced one of the very good FILTER CLAUSE which is used to apply filters in aggregate functions. </p>
<p><strong>Using FILTER, You can use different types of aggregate functions without applying any GROUP BY CLAUSE.</strong> </p>
<blockquote><p>Now Imagine, that I have one Student table and I want total number of Students based different grades.<br />
What happened without FILTER CLAUSE, We have to perform this calculation in the individual SELECT query.</p></blockquote>
<blockquote><p>But with the use of FILTER CLAUSE we can perform aggregation based on different FILTER values in a single SQL Query. </p></blockquote>
<p><strong>Below is a small demonstration of this:</strong></p>
<p><strong>Create one Student table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Students
(
	StudID INT PRIMARY KEY
	,StudentName CHARACTER VARYING
	,Marks INTEGER
);

INSERT INTO tbl_Students 
VALUES (1,'Anvesh',88),(2,'Jenny',55),(3,'Tushar',85)
,(4,'Kavita',75),(5,'Manas',42),(6,'Martin',69)
,(7,'Roy',95),(8,'Benny',92),(9,'Neevan',82)
,(10,'Lee',43),(11,'Loother',65),(12,'Eric',58);</pre> </p>
<p><strong>Apply FILTER clause to count number of Students based on Marks:</strong></p>
<pre class="crayon-plain-tag">SELECT 
	COUNT(1) AS TotalStudents 
	,COUNT(1) FILTER (WHERE Marks BETWEEN 40 AND 60) AS TotalGrade_C
	,COUNT(1) FILTER (WHERE Marks BETWEEN 60 AND 80) AS TotalGrade_B
	,COUNT(1) FILTER (WHERE Marks BETWEEN 80 AND 100) AS TotalGrade_A	
FROM tbl_Students;

/* Result:
-------------- --------------- --------------- ---------------
TotalStudents |  TotalGrade_C |  TotalGrade_B |  TotalGrade_A
--------------|---------------|---------------|---------------
      12      |       4       |       3       |       5
-------------- --------------- --------------- ---------------
 */</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/08/postgresql-9-4-using-filter-clause-multiple-count-in-one-select-query-for-different-groups-function-aggregation/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: How to Install PostgreSQL 9.4 on Ubuntu 14.04?</title>
		<link>https://www.dbrnd.com/2016/04/postgresql-how-to-install-postgresql-9-4-on-ubuntu-14-04/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 21 Apr 2016 20:15:07 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[linux]]></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>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2260</guid>

					<description><![CDATA[&#160; PostgreSQL is a powerful, open source object-relational database system. It has more than 15 years of active development and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness. I am going to share few steps on how to install PostgreSQL 9.4 on Ubuntu 14.04. First, check the [&#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%2F04%2Fpostgresql-how-to-install-postgresql-9-4-on-ubuntu-14-04%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Install%20PostgreSQL%209.4%20on%20Ubuntu%2014.04%3F" 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%2F04%2Fpostgresql-how-to-install-postgresql-9-4-on-ubuntu-14-04%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Install%20PostgreSQL%209.4%20on%20Ubuntu%2014.04%3F" 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%2F04%2Fpostgresql-how-to-install-postgresql-9-4-on-ubuntu-14-04%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Install%20PostgreSQL%209.4%20on%20Ubuntu%2014.04%3F" 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%2F04%2Fpostgresql-how-to-install-postgresql-9-4-on-ubuntu-14-04%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Install%20PostgreSQL%209.4%20on%20Ubuntu%2014.04%3F" 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%2F04%2Fpostgresql-how-to-install-postgresql-9-4-on-ubuntu-14-04%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Install%20PostgreSQL%209.4%20on%20Ubuntu%2014.04%3F" 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%2F04%2Fpostgresql-how-to-install-postgresql-9-4-on-ubuntu-14-04%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Install%20PostgreSQL%209.4%20on%20Ubuntu%2014.04%3F" 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%2F04%2Fpostgresql-how-to-install-postgresql-9-4-on-ubuntu-14-04%2F&#038;title=PostgreSQL%3A%20How%20to%20Install%20PostgreSQL%209.4%20on%20Ubuntu%2014.04%3F" data-a2a-url="https://www.dbrnd.com/2016/04/postgresql-how-to-install-postgresql-9-4-on-ubuntu-14-04/" data-a2a-title="PostgreSQL: How to Install PostgreSQL 9.4 on Ubuntu 14.04?"></a></p><p><a href="https://www.dbrnd.com/wp-content/uploads/2016/04/elephant-kruger.jpg" rel="attachment wp-att-2263"><img fetchpriority="high" decoding="async" class="alignleft wp-image-2263 size-medium" title="PostgreSQL Elephant" src="https://www.dbrnd.com/wp-content/uploads/2016/04/elephant-kruger-300x218.jpg" alt="PostgreSQL Elephant" width="300" height="218" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/elephant-kruger-300x218.jpg 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/elephant-kruger-150x109.jpg 150w, https://www.dbrnd.com/wp-content/uploads/2016/04/elephant-kruger.jpg 622w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>&nbsp;</p>
<p><em><a href="http://www.postgresql.org/about/" target="_blank">PostgreSQL is a powerful,</a> open source object-relational database system. It has more than 15 years of active development and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness.</em></p>
<p>I am going to share few steps on how to install PostgreSQL 9.4 on Ubuntu 14.04.</p>
<p><strong>First, check the version of Ubuntu:</strong><br />
<pre class="crayon-plain-tag">lsb_release -sc</pre>
<p><strong>You need to add the latest PostgreSQL repository for the latest version, otherwise It will install PostgreSQL 9.3. This is for trusty version.</strong><br />
<pre class="crayon-plain-tag">sudo add-apt-repository "deb https://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main"</pre>
<p><strong>Update and Install PostgreSQL 9.4:</strong><br />
<pre class="crayon-plain-tag">sudo apt-get update
sudo apt-get install postgresql-9.4</pre>
<p><strong>Default postgres super user and postgres database is created. You need to set a password for the postgres super user. </strong><br />
<pre class="crayon-plain-tag">ubuntu@:~$ sudo passwd postgres
Enter new UNIX password:****
Retype new UNIX password:****
passwd: password updated successfully</pre>
<p><strong>If service is not started, you can start the PostgreSQL service. </strong><br />
<pre class="crayon-plain-tag">sudo service postgresql start</pre>
<p><strong>Connect PostgreSQL server using postgres user:</strong><br />
<pre class="crayon-plain-tag">ubuntu@:~$ su postgres
Password:****</pre>
<p><strong>Create a sample database:</strong><br />
<pre class="crayon-plain-tag">createdb database_name</pre>
<p><strong>Connect to that database:</strong><br />
<pre class="crayon-plain-tag">psql -d database_name</pre>
<p><strong>Create a sample table:</strong><br />
<pre class="crayon-plain-tag">create table Test (rno integer);</pre>
<p><strong>Exit to database session:</strong><br />
<pre class="crayon-plain-tag">\q</pre>
<p><strong>Exit to PostgreSQL server:</strong><br />
<pre class="crayon-plain-tag">exit</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Using json_agg() aggregate table data into a JSON formatted array</title>
		<link>https://www.dbrnd.com/2016/03/postgresql-using-json_agg-aggregate-table-data-into-a-json-formatted-array/</link>
					<comments>https://www.dbrnd.com/2016/03/postgresql-using-json_agg-aggregate-table-data-into-a-json-formatted-array/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 25 Mar 2016 18:08: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_agg]]></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=2173</guid>

					<description><![CDATA[Recently, PostgreSQL introduced JSON data type which is very powerful to manipulate JSON formatted data. I published a couple of articles on JSON Data Type. You can start from here. In this post, I am showing aggregation of table data into a JSON formatted array using json_agg(). Our requirement is to aggregate non json formatted [&#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%2F03%2Fpostgresql-using-json_agg-aggregate-table-data-into-a-json-formatted-array%2F&amp;linkname=PostgreSQL%3A%20Using%20json_agg%28%29%20aggregate%20table%20data%20into%20a%20JSON%20formatted%20array" 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%2F03%2Fpostgresql-using-json_agg-aggregate-table-data-into-a-json-formatted-array%2F&amp;linkname=PostgreSQL%3A%20Using%20json_agg%28%29%20aggregate%20table%20data%20into%20a%20JSON%20formatted%20array" 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%2F03%2Fpostgresql-using-json_agg-aggregate-table-data-into-a-json-formatted-array%2F&amp;linkname=PostgreSQL%3A%20Using%20json_agg%28%29%20aggregate%20table%20data%20into%20a%20JSON%20formatted%20array" 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%2F03%2Fpostgresql-using-json_agg-aggregate-table-data-into-a-json-formatted-array%2F&amp;linkname=PostgreSQL%3A%20Using%20json_agg%28%29%20aggregate%20table%20data%20into%20a%20JSON%20formatted%20array" 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%2F03%2Fpostgresql-using-json_agg-aggregate-table-data-into-a-json-formatted-array%2F&amp;linkname=PostgreSQL%3A%20Using%20json_agg%28%29%20aggregate%20table%20data%20into%20a%20JSON%20formatted%20array" 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%2F03%2Fpostgresql-using-json_agg-aggregate-table-data-into-a-json-formatted-array%2F&amp;linkname=PostgreSQL%3A%20Using%20json_agg%28%29%20aggregate%20table%20data%20into%20a%20JSON%20formatted%20array" 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%2F03%2Fpostgresql-using-json_agg-aggregate-table-data-into-a-json-formatted-array%2F&#038;title=PostgreSQL%3A%20Using%20json_agg%28%29%20aggregate%20table%20data%20into%20a%20JSON%20formatted%20array" data-a2a-url="https://www.dbrnd.com/2016/03/postgresql-using-json_agg-aggregate-table-data-into-a-json-formatted-array/" data-a2a-title="PostgreSQL: Using json_agg() aggregate table data into a JSON formatted array"></a></p><p>Recently, PostgreSQL introduced JSON data type which is very powerful to manipulate JSON formatted data. </p>
<p>I published a couple of articles on JSON Data Type.<br />
<a href="https://www.dbrnd.com/2016/02/postgresql-9-4-the-json-data-type-is-awesome-part-1/" target="_blank"><strong>You can start from here. </strong></a></p>
<p>In this post, I am showing aggregation of table data into a JSON formatted array using json_agg().</p>
<p>Our requirement is to aggregate non json formatted data into JSON array and even also required to aggregate JSON formatted data.</p>
<p>I prepared a small demonstration using json_agg().</p>
<p><strong>Create a table with sample JSON formatted data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestJSON
(
	ID INTEGER PRIMARY KEY
	,DepartName VARCHAR(250)
	,EmployeeDetails JSONB
);</pre> </p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestJSON
VALUES 
(
	1
	,'Sales'
	,'
	{"employees":[
	    {"firstName":"Anvesh", "lastName":"Patel"}	  
	]}'
)
,(
	2
	,'Production'
	,'
	{"employees":[	    
	    {"firstName":"Nancy", "lastName":"Shah"}
	]}'
);</pre> </p>
<p><strong>Aggregates JSON formatted data:</strong></p>
<pre class="crayon-plain-tag">SELECT json_agg(employeedetails) AS JsonArray FROM tbl_TestJSON;

JsonArray
------------------------
[{"employees": [{"lastName": "Patel", "firstName": "Anvesh"}]}, {"employees": [{"lastName": "Shah", "firstName": "Nancy"}]}]</pre> </p>
<p><strong>Aggregates non JSON formatted data:</strong></p>
<pre class="crayon-plain-tag">SELECT json_agg(DepartName) AS JsonArray FROM tbl_TestJSON;

JsonArray
------------------------
["Sales", "Production"]</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/03/postgresql-using-json_agg-aggregate-table-data-into-a-json-formatted-array/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<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>
		<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-6aa2bd63ae159397700972/] 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>
		<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 loading="lazy" 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="auto, (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>
		<item>
		<title>PostgreSQL: New Powerful feature of PostgreSQL 9.4</title>
		<link>https://www.dbrnd.com/2015/11/postgresql-new-powerful-feature-of-postgresql-9-4-2/</link>
					<comments>https://www.dbrnd.com/2015/11/postgresql-new-powerful-feature-of-postgresql-9-4-2/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 25 Nov 2015 04:26:41 +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 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=1072</guid>

					<description><![CDATA[In this post, I am sharing a short note on the new feature of PostgreSQL 9.4. PostgreSQL 9.4 has one of the best features that I have liked it JSON data type. PostgreSQL 9.4 New Features: JSONB Binary JSON Storage Data Type: You don&#8217;t require to take a decision between RDBMS and NOSQL because you [&#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%2F2015%2F11%2Fpostgresql-new-powerful-feature-of-postgresql-9-4-2%2F&amp;linkname=PostgreSQL%3A%20New%20Powerful%20feature%20of%20PostgreSQL%209.4" 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%2F2015%2F11%2Fpostgresql-new-powerful-feature-of-postgresql-9-4-2%2F&amp;linkname=PostgreSQL%3A%20New%20Powerful%20feature%20of%20PostgreSQL%209.4" 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%2F2015%2F11%2Fpostgresql-new-powerful-feature-of-postgresql-9-4-2%2F&amp;linkname=PostgreSQL%3A%20New%20Powerful%20feature%20of%20PostgreSQL%209.4" 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%2F2015%2F11%2Fpostgresql-new-powerful-feature-of-postgresql-9-4-2%2F&amp;linkname=PostgreSQL%3A%20New%20Powerful%20feature%20of%20PostgreSQL%209.4" 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%2F2015%2F11%2Fpostgresql-new-powerful-feature-of-postgresql-9-4-2%2F&amp;linkname=PostgreSQL%3A%20New%20Powerful%20feature%20of%20PostgreSQL%209.4" 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%2F2015%2F11%2Fpostgresql-new-powerful-feature-of-postgresql-9-4-2%2F&amp;linkname=PostgreSQL%3A%20New%20Powerful%20feature%20of%20PostgreSQL%209.4" 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%2F2015%2F11%2Fpostgresql-new-powerful-feature-of-postgresql-9-4-2%2F&#038;title=PostgreSQL%3A%20New%20Powerful%20feature%20of%20PostgreSQL%209.4" data-a2a-url="https://www.dbrnd.com/2015/11/postgresql-new-powerful-feature-of-postgresql-9-4-2/" data-a2a-title="PostgreSQL: New Powerful feature of PostgreSQL 9.4"></a></p><p>In this post, I am sharing a short note on the new feature of PostgreSQL 9.4.</p>
<p>PostgreSQL 9.4 has one of the best features that I have liked it JSON data type.</p>
<p><strong>PostgreSQL 9.4 New Features:</strong></p>
<ul>
<li><strong>JSONB Binary JSON Storage Data Type:</strong> You don&#8217;t require to take a decision between RDBMS and NOSQL because you can have now both at the same time.</li>
<li><strong>Replication Slots:</strong> The information is available to the primary server, when the standby server is offline or disconnected.</li>
<li><strong>Changeset Streaming/Logical decoding:</strong><br />
It supplies a new API for filtering, reading and manipulating the replication stream.</li>
<li><strong>GIN indexes now faster and smaller:</strong><br />
pg_prewarm: This is also one of the good parameters. When you restart your PostgreSQL Server, the shared buffer is empty again. But using this parameter you can take backup of buffer as well.</li>
<li><strong>ALTER SYSTEM:</strong> you can change your system setting using this ALTER SYSTEM and don&#8217;t require to edit postgresql.conf.</li>
<li><strong>REFRESH MATERIALIZED VIEW CONCURRENTLY.</strong></li>
<li><strong>Improvement in Updatable view.</strong></li>
<li><strong>WITH ORDINALITY:</strong> A column containing an ordered sequence of numbers is added.</li>
<li><strong>Added some new aggregate features.</strong></li>
</ul>
<p><a href="https://wiki.postgresql.org/wiki/What's_new_in_PostgreSQL_9.4" target="_blank">Reference taken from this URL:</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/11/postgresql-new-powerful-feature-of-postgresql-9-4-2/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
