<?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>node &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/node/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 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>
