title: UNION ALL, cast NULL as double precision, Postgres
body: <p>In postgres, I'm getting an error when I try to union two tables where one table has a column (<code>Amount</code>) containing <code>double precision</code> data type, and the other table does not have a matching column and I'd like the records from that table to just have <code>NULL</code> in the <code>Amount</code> field.</p>
  
  <p><strong>Error:</strong> </p>
  
  <blockquote>
    <p>"union types text and double precision cannot be matched postgres"</p>
  </blockquote>
  
  <p><strong>Pseudo-code:</strong></p>
  
  <pre><code>SELECT * FROM (
  
  SELECT
     t1.Amount AS 'amount',
     NULL::DATE AS 'date'
  FROM Table1 AS t1
  UNION ALL
  
  SELECT
     /* next line is the issue */
     NULL AS 'amount',
     t2.Date AS 'date'
  FROM Table2 AS t2
  
  ) AS FOO
  </code></pre>
  
  <p>I feel fairly certain this solution is a simple casting problem but could not find anything from searching. How do I do the equivalent of <code>NULL::DOUBLE</code> in postgres?</p>
  
  <p><strong>EDIT::POSTERITY</strong></p>
  
  <p>The accepted answer from @klin and @a_horse_with_no_name's comment that points to a "historical" postgres cast expression <code>::</code> where the <a href="https://www.postgresql.org/docs/current/static/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS" rel="nofollow noreferrer">syntax is equivalent</a>:</p>
  
  <pre><code>CAST ( expression AS type )  
  expression::type
  </code></pre>
  
  <p>And, here is a list of the <a href="https://www.postgresql.org/docs/9.5/static/datatype.html" rel="nofollow noreferrer">postgres data types</a>.</p>