<?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>Tequila Fish &#187; sql</title>
	<atom:link href="http://www.tequilafish.com/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tequilafish.com</link>
	<description>Ran-dumb ramblings of me...</description>
	<lastBuildDate>Thu, 26 Jan 2012 23:30:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PostgreSQL: Determine if a column exists or not.</title>
		<link>http://www.tequilafish.com/2007/02/23/postgresql-determine-if-a-column-exists-or-not/</link>
		<comments>http://www.tequilafish.com/2007/02/23/postgresql-determine-if-a-column-exists-or-not/#comments</comments>
		<pubDate>Sat, 24 Feb 2007 00:05:00 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[postgre]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.tequilafish.com/2007/02/23/postgresql-determine-if-a-column-exists-or-not/</guid>
		<description><![CDATA[Here's a quick query you can run to determine whether or not a particular column in a table exists or not: SELECT attname FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'YOURTABLENAME') AND attname = 'YOURCOLUMNNAME'; Of course, replace YOURTABLENAME and YOURCOLUMNNAME with the proper values. If a row is returned, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.tequilafish.com%2F2007%2F02%2F23%2Fpostgresql-determine-if-a-column-exists-or-not%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.tequilafish.com%2F2007%2F02%2F23%2Fpostgresql-determine-if-a-column-exists-or-not%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Here's a quick query you can run to determine whether or not a particular column in a table exists or not:</p>
<p><code>SELECT attname FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'YOURTABLENAME') AND attname = 'YOURCOLUMNNAME';</code></p>
<p>Of course, replace <tt>YOURTABLENAME</tt> and <tt>YOURCOLUMNNAME</tt> with the proper values.  If a row is returned, a column with that name exists, otherwise it does not.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tequilafish.com/2007/02/23/postgresql-determine-if-a-column-exists-or-not/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PostgreSQL: DB Error: constraint violation.</title>
		<link>http://www.tequilafish.com/2006/03/12/postgresql-db-error-constraint-violation/</link>
		<comments>http://www.tequilafish.com/2006/03/12/postgresql-db-error-constraint-violation/#comments</comments>
		<pubDate>Sun, 12 Mar 2006 21:44:45 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[postgre]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.tequilafish.com/2006/03/12/postgresql-db-error-constraint-violation/</guid>
		<description><![CDATA[When inserting a row into a PostgreSQL database table, PHP's PEAR DB class was giving me the following error: DB Error: constraint violation After some research I found out that when we moved the tables to a new database server, the SEQUENCE values were not updated, causing this problem. Sequences are the equivalent of MySQL's [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.tequilafish.com%2F2006%2F03%2F12%2Fpostgresql-db-error-constraint-violation%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.tequilafish.com%2F2006%2F03%2F12%2Fpostgresql-db-error-constraint-violation%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>When inserting a row into a PostgreSQL database table, PHP's PEAR DB class was giving me the following error:<br />
<code>DB Error: constraint violation</code><br />
After some research I found out that when we moved the tables to a new database server, the <tt>SEQUENCE</tt> values were not updated, causing this problem.  Sequences are the equivalent of MySQL's <tt>auto-increment</tt> and are used to generate a unique identity value for newly inserted rows.</p>
<p>Because our table already had plenty of rows in it and the sequence value was not in sync, the insert would fail because the ID generated for it by the sequence already existed in the database.  This is an easy fix, all you have to do is update the sequence value to be back in sync with your data.  Simply run the following command in <tt>psql</tt> to bring everything back into sync:<br />
<code>select setval('your_table_id_seq', (SELECT max(id) FROM your_table) + 1);</code><br />
Of course you will want to substitute your own sequence, table, and field values into this command.  Once you've done this everything will be back in sync and you'll be able to insert new rows into your DB once again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tequilafish.com/2006/03/12/postgresql-db-error-constraint-violation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

