<?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>Partial Index Constraint &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/partial-index-constraint/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, 22 Aug 2016 17:57:15 +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: Example of Partial UNIQUE Composite Index</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-example-of-partial-unique-composite-index-to-avoid-duplicate-records/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 22 Aug 2016 17:56:07 +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[Partial Index Constraint]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></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[UNIQUE CONSTRAINT]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3549</guid>

					<description><![CDATA[The Data validation is always a major concern of any Database System. We all know about the UNIQUE constraint which prevents the duplicate records. One of the Previous article, I have already shared one small note about the UNIQUE Index of PostgreSQL. PostgreSQL: Composite UNIQUE Constraint does not consider NULL Values In this post, I [&#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-example-of-partial-unique-composite-index-to-avoid-duplicate-records%2F&amp;linkname=PostgreSQL%3A%20Example%20of%20Partial%20UNIQUE%20Composite%20Index" 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-example-of-partial-unique-composite-index-to-avoid-duplicate-records%2F&amp;linkname=PostgreSQL%3A%20Example%20of%20Partial%20UNIQUE%20Composite%20Index" 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-example-of-partial-unique-composite-index-to-avoid-duplicate-records%2F&amp;linkname=PostgreSQL%3A%20Example%20of%20Partial%20UNIQUE%20Composite%20Index" 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-example-of-partial-unique-composite-index-to-avoid-duplicate-records%2F&amp;linkname=PostgreSQL%3A%20Example%20of%20Partial%20UNIQUE%20Composite%20Index" 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-example-of-partial-unique-composite-index-to-avoid-duplicate-records%2F&amp;linkname=PostgreSQL%3A%20Example%20of%20Partial%20UNIQUE%20Composite%20Index" 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-example-of-partial-unique-composite-index-to-avoid-duplicate-records%2F&amp;linkname=PostgreSQL%3A%20Example%20of%20Partial%20UNIQUE%20Composite%20Index" 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-example-of-partial-unique-composite-index-to-avoid-duplicate-records%2F&#038;title=PostgreSQL%3A%20Example%20of%20Partial%20UNIQUE%20Composite%20Index" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-example-of-partial-unique-composite-index-to-avoid-duplicate-records/" data-a2a-title="PostgreSQL: Example of Partial UNIQUE Composite Index"></a></p><p>The Data validation is always a major concern of any Database System.<br />
We all know about the UNIQUE constraint which prevents the duplicate records. </p>
<p>One of the Previous article, I have already shared one small note about the UNIQUE Index of PostgreSQL. </p>
<blockquote class="wp-embedded-content" data-secret="mBxVzjd76w"><p><a href="https://www.dbrnd.com/2016/01/postgresql-composite-unique-constraint-does-not-consider-null-values/">PostgreSQL: Composite UNIQUE Constraint does not consider NULL Values</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/01/postgresql-composite-unique-constraint-does-not-consider-null-values/embed/#?secret=mBxVzjd76w" data-secret="mBxVzjd76w" width="600" height="338" title="&#8220;PostgreSQL: Composite UNIQUE Constraint does not consider NULL Values&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>In this post, I am sharing a similar post for Partial Unique Index of PostgreSQL. </p>
<p>For example, I want to stop duplicate Student Grages for particular Student Division only.</p>
<p><strong>Create a sample table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Students
(
	StudID INT 
	,StudName CHARACTER VARYING 
	,StudDivision CHARACTER VARYING
	,StudGrade CHAR(1)
);</pre> </p>
<p><strong>Create a Partial UNIQUE Index:</strong></p>
<pre class="crayon-plain-tag">CREATE UNIQUE INDEX tbl_Students_StudGrade ON tbl_Students (COALESCE(StudDivision,''),COALESCE(StudGrade,'')) 
WHERE StudDivision IN ('First','Second','Third');</pre> </p>
<p><strong>Insert few sample records:</strong><br />
As we have creted Partial index so we can insert only unique combination of StudDivision (First,Second,Third) and StudGrade.</p>
<pre class="crayon-plain-tag">INSERT INTO tbl_Students
VALUES 
(1,'Anvesh','First','A')
,(2,'Jeeny','Second','B')
,(3,'Roy','Third','B')
,(4,'Mukesh','First','C')
,(5,'Martin','Second','C')
,(6,'Kavita','Third','A');</pre> </p>
<p><strong>Try to insert few Invalid records:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_Students
VALUES 
(7,'Rajesh','First','A')
,(8,'Nile','Second','B');</pre> </p>
<p><strong>Try to insert few records which are not validated by Partition Index:</strong><br />
We can insert duplicate records StudGrade + StudDivision for other StudDivisions except Partial StudDivision.</p>
<pre class="crayon-plain-tag">INSERT INTO tbl_Students
VALUES 
(7,'Dimpi','Fourth','C')
,(8,'Bony','Fourth','C');</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
