<?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>Yet another blog about PHP, HTML and CSS &#187; PostgreSQL</title>
	<atom:link href="http://blog.pepa.info/php-html-css/category/postgresql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pepa.info</link>
	<description>Petr 'PePa' Pavel</description>
	<lastBuildDate>Thu, 19 Aug 2010 18:17:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to deal with IMMUTABLE error in indexes that work with timestamps</title>
		<link>http://blog.pepa.info/php-html-css/postgresql/how-to-deal-with-immutable-error-in-indexes-that-work-with-timestamps/</link>
		<comments>http://blog.pepa.info/php-html-css/postgresql/how-to-deal-with-immutable-error-in-indexes-that-work-with-timestamps/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 12:14:54 +0000</pubDate>
		<dc:creator>Petr 'PePa' Pavel</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://blog.pepa.info/2008/03/postgresql/how-to-deal-with-immutable-error-in-indexes-that-work-with-timestamps/</guid>
		<description><![CDATA[Say that in an older version of PostgreSQL you had an index like this: CREATE INDEX logTypeDay ON myLog &#40;eventType, date_trunc&#40;&#8216;day&#8217;, creationTime&#41;&#41;; and now after upgrading to 8.1+ you&#8217;re getting: ERROR: functions in index expression must be marked IMMUTABLE The reason is that date_trunc may return different results based on the current time zone. There&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Say that in an older version of PostgreSQL you had an index like this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">CREATE</span> <span class="kw1">INDEX</span> logTypeDay <span class="kw1">ON</span> myLog <span class="br0">&#40;</span>eventType, date_trunc<span class="br0">&#40;</span><span class="st0">&#8216;day&#8217;</span>, creationTime<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>and now after upgrading to 8.1+ you&#8217;re getting:<br />
<strong> ERROR:  functions in index expression must be marked IMMUTABLE</strong></p>
<p><span id="more-16"></span>The reason is that date_trunc may return different results based on the current time zone. There&#8217;s an example query in <a target="_blank" href="http://archives.postgresql.org/pgsql-hackers/2004-10/msg00030.php">PostgreSQL Mailing List Archives</a> that you can run to believe.</p>
<p>If you are absolutely sure that you will always access your data with the same time zone you can redefine your index like this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">CREATE</span> <span class="kw1">INDEX</span> logTypeDay <span class="kw1">ON</span> myLog <span class="br0">&#40;</span>eventType, date_trunc<span class="br0">&#40;</span><span class="st0">&#8216;day&#8217;</span>::text, creationTime AT TIME ZONE <span class="st0">&#8216;Europe/Prague&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>The whole immutable business with indexes containing functions that process timestamps is well explained in these threads:<br />
<a target="_blank" href="http://archives.postgresql.org/pgsql-interfaces/2004-06/msg00045.php"> http://archives.postgresql.org/pgsql-interfaces/&#8230;/msg00045.php</a><br />
<a target="_blank" href="http://www.webservertalk.com/archive307-2007-2-1817943.html"> http://www.webservertalk.com/archive307-2007-2-1817943.html</a><br />
<a target="_blank" href="http://www.mydatabasesupport.com/forums/postgresql/209895-re-date_trunc-d-timestamp-index-possible.html"> http://www.mydatabasesupport.com/forums/&#8230;-possible.html</a></p>
<p>All credit goes to Tom Lane. I admire him for being always so patient and polite, and for spending so much of his valuable time with talking to users. I would love to link to his homepage but I failed to find it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pepa.info/php-html-css/postgresql/how-to-deal-with-immutable-error-in-indexes-that-work-with-timestamps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
