title: Postgresql complains when interval is result of string concatenation
body: <p>Using <a href="https://stackoverflow.com/questions/16113372/pgsql-turning-day-of-year-back-into-date">this answer</a> to convert a (date + interval) into a date. Only in my case the date and the interval are strings that are the result of slice&amp;dice of other strings. The problem is that it works when I construct the string for the <code>date</code> but not for the <code>interval</code>.</p>
  
  <p>So, the following statements work:</p>
  
  <pre><code>SELECT (date '2013-01-01');
  SELECT (interval '53 days');
  SELECT (date '2013-01-01' + interval '53 days');
  </code></pre>
  
  <p>Now I want to synthesize the strings that are passed after <code>date</code> and <code>interval</code> by <code>substring</code>-ing some other string (think stored procedure where we operate on a passed parameter):</p>
  
  <p>This works for <code>date</code>:</p>
  
  <pre><code>SELECT date (substring('2015015' from 1 for 4)||'-01-01')::text;
  </code></pre>
  
  <p>But it fails for <code>interval</code>:</p>
  
  <pre><code>SELECT interval (substring('2015015' from 5)||' days')::text;
  </code></pre>
  
  <p>with error message:</p>
  
  <pre><code>ERROR:  syntax error at or near "substring"
  </code></pre>
  
  <p>It actually works if I cast explicitly to <code>interval</code> either with <code>CAST(x as INTERVAL)</code> or equivalently with <code>x::interval</code>:</p>
  
  <pre><code>SELECT CAST((substring('2015015' from 5)||' days')::text AS INTERVAL);
  </code></pre>
  
  <p>or equivalently:</p>
  
  <pre><code>SELECT ((substring('2015015' from 5)||' days')::text)::interval;
  </code></pre>
  
  <p>Why does the <code>date TEXT</code> work regardless of how the <code>TEXT</code> is placed there, but the same with <code>interval</code> only works with direct text, but not with synthesized one.</p>
  
  <p>I'm on Postgres 9.4.</p>