<?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>sequence number &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/sequence-number/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>Sun, 27 Nov 2016 15:36:41 +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-6ab55f8ed707f184871904/] 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>
	</channel>
</rss>
