title: postgres `order by` argument type
body: <p>What is the argument type for the <code>order by</code> clause in Postgresql?</p>
  
  <p>I came across a very strange behaviour (using Postgresql 9.5). Namely, the query</p>
  
  <pre><code>select * from unnest(array[1,4,3,2]) as x order by 1;
  </code></pre>
  
  <p>produces <code>1,2,3,4</code> as expected. However the query</p>
  
  <pre><code>select * from unnest(array[1,4,3,2]) as x order by 1::int;
  </code></pre>
  
  <p>produces <code>1,4,3,2</code>, which seems strange. Similarly, whenever I replace <code>1::int</code> with whatever function (e.g. <code>greatest(0,1)</code>) or even <code>case</code> operator, the results are unordered (on the contrary to <a href="https://stackoverflow.com/questions/6427381/sql-order-by-with-case-with-union-all">what I would expect</a>).</p>
  
  <p>So which type should an argument of <code>order by</code> have, and how do I get the expected behaviour?</p>