<?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>unnest &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/unnest/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>Mon, 20 Nov 2017 05:50:55 +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.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-6ab55e29a36a4070662264/] 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 XML Type</title>
		<link>https://www.dbrnd.com/2015/05/postgresql-xml-type/</link>
					<comments>https://www.dbrnd.com/2015/05/postgresql-xml-type/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 22 May 2015 15:53:55 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[datatype]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[unnest]]></category>
		<category><![CDATA[XML]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=175</guid>

					<description><![CDATA[In this post, I am sharing a demonstration on the XML data type of PostgreSQL. Explain with the sample example. What is XML Type ? The XML Data type is used to store XML data. XML is well-formed storage structure of data. You can store multiple nodes into a single XML column. You can store [&#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%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" 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%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" 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%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" 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%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" 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%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" 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%2F05%2Fpostgresql-xml-type%2F&amp;linkname=PostgreSQL%20XML%20Type" 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%2F05%2Fpostgresql-xml-type%2F&#038;title=PostgreSQL%20XML%20Type" data-a2a-url="https://www.dbrnd.com/2015/05/postgresql-xml-type/" data-a2a-title="PostgreSQL XML Type"></a></p><p>In this post, I am sharing a demonstration on the XML data type of PostgreSQL.</p>
<p>Explain with the sample example.</p>
<p><b>What is XML Type ?</b></p>
<p>The XML Data type is used to store XML data. XML is well-formed storage structure of data. You can store multiple nodes into a single XML column. You can store data in hierarchical format.</p>
<p><b>E.g, </b></p>
<p>User preferences table, in which User can select multiple preferences and even User can create custom choices for them.</p>
<p>Now, how you can store this preferences data for those Users.</p>
<p>Simple, create one XML column and store all User preferences id into this. like,</p>
<p>&lt;preferences&gt;&lt;id&gt;1&lt;/id&gt;&lt;id&gt;2&lt;/id&gt;&lt;id&gt;4&lt;/id&gt;&lt;/preferences&gt;.</p>
<p><b>Below is a demonstration of XML with PostgreSQL. </b></p>
<p><b>Basically you can store XML data with one child node or with different child node.</b></p>
<div>
<p><b><span style="font-size: x-large;">Les&#8217;s First start with one child node:<br />
</span></b> Create table with XML type:</p><pre class="crayon-plain-tag">CREATE TABLE XMLTEST (Name XML);</pre><p>
Now Insert XML Data.</p><pre class="crayon-plain-tag">INSERT INTO XMLTEST 
VALUES
('
    &lt;Root&gt;
          &lt;Sub&gt;abc&lt;/Sub&gt;
          &lt;Sub&gt;xyz&lt;/Sub&gt;
          &lt;Sub&gt;pqr&lt;/Sub&gt;
          &lt;Sub&gt;cdf&lt;/Sub&gt;
   &lt;/Root&gt;
');</pre><p>
Select data from XMLTEST:</p><pre class="crayon-plain-tag">SELECT *FROM XMLTEST</pre><p>
You can find above full XML into one column.</p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultOne.png"><img fetchpriority="high" decoding="async" class="aligncenter wp-image-178 size-full" title="XML Postgres Result One" src="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultOne.png" alt="XMLPostgresResultOne" width="737" height="138" srcset="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultOne.png 737w, https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultOne-300x56.png 300w, https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultOne-150x28.png 150w" sizes="(max-width: 737px) 100vw, 737px" /></a></p>
<p><b>Now, time to parse this XML column using unnest() function of PostgreSQL. </b></p><pre class="crayon-plain-tag">SELECT unnest(xpath('.//Sub/text()', Name::xml))::text AS XMLDATA FROM XMLTEST;</pre><p>
Result is:</p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultTwo.png"><img decoding="async" class="aligncenter wp-image-180 size-full" title="XML Postgres Result Two" src="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultTwo.png" alt="XMLPostgresResultTwo" width="149" height="201" /></a></p>
<div>
<p>You can see this is four rows now, as we have stored different four values into one XML Column and after parse, we can see those four values in the form of different row.</p>
</div>
<div>
<p><b><span style="font-size: x-large;">Demonstration of different child node:</span></b></p><pre class="crayon-plain-tag">INSERT INTO XMLTEST VALUES
   ('
     &lt;BasicDetails&gt;
        &lt;Name&gt;Anvesh&lt;/Name&gt;
        &lt;City&gt;Hyderabad&lt;/City&gt;
        &lt;Gender&gt;Male&lt;/Gender&gt;
        &lt;Age&gt;27&lt;/Age&gt;
     &lt;/BasicDetails&gt; 
   ');

SELECT 
 unnest(xpath('//Name/text()', Name::XML)) AS Name
 ,unnest(xpath('//City/text()', Name::XML)) AS City
 ,unnest(xpath('//Gender/text()', Name::XML)) AS Gender
 ,unnest(xpath('//Age/text()', Name::XML)) AS Age
FROM XMLTEST;</pre><p>
</div>
<p><b>Result is :</b></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultThree.png"><img decoding="async" class="aligncenter wp-image-179 size-full" title="XML Postgres Result Three" src="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultThree.png" alt="XMLPostgresResultThree" width="356" height="169" srcset="https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultThree.png 356w, https://www.dbrnd.com/wp-content/uploads/2015/05/XMLPostgresResultThree-300x142.png 300w" sizes="(max-width: 356px) 100vw, 356px" /></a></p>
<p>In the above code, we inserted an XML data with different child nodes.</p>
<p>You can see the result of one row with the various columns for the different child nodes.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/05/postgresql-xml-type/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
