<?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>entwicklungsgedanken &#187; SQL</title>
	<atom:link href="http://www.entwicklungsgedanken.de/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.entwicklungsgedanken.de</link>
	<description>Verschiedene Gedanken rund um die Softwareentwicklung</description>
	<lastBuildDate>Mon, 09 Jan 2012 14:47:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Solving NULL values are recognized as text-values within dynamic queries in PostgresSQL</title>
		<link>http://www.entwicklungsgedanken.de/2010/07/29/solving-null-values-are-recognized-as-text-values-within-dynamic-queries-in-postgressql/</link>
		<comments>http://www.entwicklungsgedanken.de/2010/07/29/solving-null-values-are-recognized-as-text-values-within-dynamic-queries-in-postgressql/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 11:09:20 +0000</pubDate>
		<dc:creator>Eric Bartels</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[dynamic query]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[NULL]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">http://www.entwicklungsgedanken.de/?p=435</guid>
		<description><![CDATA[I&#8217;ve written a dynamic query which is finally executed via EXECUTE my_dynamic_query; The query contained a select list in which two columns should always be NULL. -- ... stuff before dynamic_select_cols := 'tbl1.foo, tbl1.bar, null AS theAlias1, null AS theAlias2, tbl2.foo2'; -- ... stuff after combining the dynamic queries EXECUTE my_dynamic_query; In my case the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written a dynamic query which is finally executed via <code>EXECUTE my_dynamic_query;</code> The query contained a select list in which two columns should always be <code>NULL</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- ... stuff before</span>
dynamic_select_cols :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'tbl1.foo, tbl1.bar, null AS theAlias1, null AS theAlias2, tbl2.foo2'</span>;
<span style="color: #808080; font-style: italic;">-- ... stuff after combining the dynamic queries</span>
<span style="color: #993333; font-weight: bold;">EXECUTE</span> my_dynamic_query;</pre></div></div>

<p>In my case the result of the query will be inserted in a <a href="http://www.postgresql.org/docs/8.4/interactive/sql-createtable.html">temporary table</a> in memory. The destination column for <code>theAlias1</code> is of type <code>INTEGER</code>. When executing the query PostgreSQL gives me an error:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">column <span style="color: #ff0000;">&quot;theAlias1&quot;</span> is of <span style="color: #7a0874; font-weight: bold;">type</span> integer but expression is of <span style="color: #7a0874; font-weight: bold;">type</span> text</pre></div></div>

<p>So there is something wrong when the query is parsed, evaluated and executed.</p>
<p>Solving this was easy with the use of <a href="http://www.postgresql.org/docs/8.4/interactive/functions-conditional.html">NULLIF</a>. Zero equals zero so <code>NULL</code> is returned. Just as expected.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- ... stuff before</span>
dynamic_select_cols :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'tbl1.foo, tbl1.bar, NULLIF(0, 0) AS theAlias1, NULLIF(0, 0) AS theAlias2, tbl2.foo2'</span>;
<span style="color: #808080; font-style: italic;">-- ... stuff after combining the dynamic queries</span>
<span style="color: #993333; font-weight: bold;">EXECUTE</span> my_dynamic_query;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.entwicklungsgedanken.de/2010/07/29/solving-null-values-are-recognized-as-text-values-within-dynamic-queries-in-postgressql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Value too long error in PostgreSQL inside a plpgsql-function</title>
		<link>http://www.entwicklungsgedanken.de/2009/11/03/value-too-long-error-in-postgresql-inside-a-plpgsql-function/</link>
		<comments>http://www.entwicklungsgedanken.de/2009/11/03/value-too-long-error-in-postgresql-inside-a-plpgsql-function/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 18:13:47 +0000</pubDate>
		<dc:creator>Eric Bartels</dc:creator>
				<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[custom type]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[execute]]></category>
		<category><![CDATA[misleading]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[value too long]]></category>

		<guid isPermaLink="false">http://www.entwicklungsgedanken.de/?p=353</guid>
		<description><![CDATA[In an application I am working on I recently found errors in the applications log file. Value too long for type character varying&#40;64&#41; Within a function (written with plpgsql) a dynamic query is built and executed via sql-EXECUTE. The error PostgreSQL gives me stated out that the error was in the line containing the EXECUTE-statement. [...]]]></description>
			<content:encoded><![CDATA[<p>In an application I am working on I recently found errors in the applications log file.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Value too long <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">type</span> character varying<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">64</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Within a function (written with <code>plpgsql</code>) a dynamic query is built and executed via sql-<code>EXECUTE</code>. The error PostgreSQL gives me stated out that the error was in the line containing the <code>EXECUTE</code>-statement. But the query was of type <code>TEXT</code> so there is no length limitation. </p>
<h3>Guide me</h3>
<p>In the end it showed that the error PostgreSQL gave me was misleading. The final dynamic query itself was fine. So the sql-<code>EXECUTE</code> cannot be the cause of the error.&#160; </p>
<p>The function returns a custom (composite) type (built via PostgreSQL <code>CREATE TYPE</code>). This custom type consists of a few “columns”. One of this column was indeed of type <code>character varying(64)</code> and was simply to short to hold the data collected inside the function. </p>
<p>Fixing the data type of that column in the custom composite type fixes the error.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.entwicklungsgedanken.de/2009/11/03/value-too-long-error-in-postgresql-inside-a-plpgsql-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

