title: Combining concatenation with ORDER BY
body: <p>I have troubles in combining concatenation with order by in Postgre (9.1.9).
  Let's say, I have a table borders with 3 fields:</p>
  <pre><code>            Table &quot;borders&quot;
      Column     |         Type         | Modifiers 
  ---------------+----------------------+-----------
   country1      | character varying(4) | not null
   country2      | character varying(4) | not null
   length        | numeric              | 
  </code></pre>
  <p>The first two fields are codes of the countries and the third one is the length of the border among those countries.<br />
  The primary key is defined on the first two fields.</p>
  <p>I need to compose a select of a column that would have unique values for the whole table, in addition this column should be selected in decreasing order.
  For this I concatenate the key fields with a separator character, otherwise two different rows might give same result, like (AB, C and A, BC).</p>
  <p>So I run the following query:</p>
  <pre><code>select  country1||'_'||country2 from borders order by 1;
  </code></pre>
  <p>However in the result I see that the '_' character is omited from the sorting.
  The results looks like this:</p>
  <pre><code> ?column? 
  ----------
   A_CH
   A_CZ
   A_D
   AFG_IR
   AFG_PK
   AFG_TAD
   AFG_TJ
   AFG_TM
   AFG_UZB
   A_FL
   A_H
   A_I
   .
   .
  </code></pre>
  <p>You can see that the result is sorted as if '_' doesn't exists in the strings.</p>
  <p>If I use a letter (say 'x') as a separator - the order is correct. But I must use some special character that doesn't appear in the country1 and country2 fields, to avoid contentions.</p>
  <p>What should I do, in order to make the '_' character to be taken into account during the sorting.</p>
  <hr />
  <h3>EDIT</h3>
  <p>It turned out that the concatenation has nothing to do with the problem. The problem is that the order by simply ignores '_' character.</p>