title: "CAST" function with "DISTINCT ON" not changing the type of the field
body: <p>I have two tables parent and child . I need to join these two tables and get the results into one.
  This pid(one column in parent table) may have duplicate entries and the field type of pid is VARCHAR.
  But the field type of 'cid' in the child table is INTEGER.</p>
  
  <p>As i need distinct value i used DISTINCT ON in the patent table query. When i take union with child table,
  the query throws error because of FIELD TYPE differs(pid and cid).
  I used <code>"DISTINCT ON" (CAST(pid AS INTEGER))</code> to make the CAST same for both tables.</p>
  
  <p>But the CAST of pid is not changing. Still its shows error.
  When i use <code>"DISTINCT CAST(pid AS INTEGER))"</code> instead of <code>"DISTINCT ON"</code> no errors came, but the result(number of rows) is not correct.</p>
  
  <p>The query i used</p>
  
  <pre><code>Select DISTINCT ON (pid) pid AS id,
  first_name
  last_name AS last_name,
  email AS email
  from parent where pid IS NOT NULL
  
  UNION
  
  Select cid  AS id,
  child_first_name AS first_name,
  child_last_name AS last_name,
  child_email AS email
  from child where cid IS NOT NULL
  </code></pre>
  
  <p><strong>Is any one have idea of using "CAST" function with "DISTINCT ON".</strong></p>