title: Failed to find conversion function from unknown to text
body: <p>In one of my select statements I've got the following error:</p>
  
  <pre><code>ERROR:  failed to find conversion function from unknown to text
  ********** Error **********
  ERROR: failed to find conversion function from unknown to text
  SQL state: XX000
  </code></pre>
  
  <p>This was easy to fix using <code>cast</code>, but I do not fully understand why it happened. I will ilustrate my confusion with two simple statements.</p>
  
  <p>This one is OK:</p>
  
  <pre><code>select 'text'
  union all
  select 'text';
  </code></pre>
  
  <p>This will return error:</p>
  
  <pre><code>with t as (select 'text')    
  select * from t
  union all
  select 'text'
  </code></pre>
  
  <p>I know I can fix it easily:</p>
  
  <pre><code>with t as (select 'text'::text)    
  select * from t
  union all
  select 'text'
  </code></pre>
  
  <p>Why does the conversion fail in the second example? Is there some logic I do not understand or this will be fixed in future version of PostgreSQL?</p>
  
  <p>PostgreSQL 9.1.9</p>
  
  <p>The same behavior on PostgreSQL 9.2.4 (<a href="http://sqlfiddle.com/#!12/d41d8/1262">SQL Fiddle</a>)</p>