I have problems combining concatenation with order in Postgre (9.1.9). Say I have a table border with three fields:
Table "borders" Column | Type | Modifiers ---------------+----------------------+----------- country1 | character varying(4) | not null country2 | character varying(4) | not null length | numeric |
The first two fields are country codes, and the third is the length of the border between these countries.
The primary key is defined for the first two fields.
I need to make a choice of a column that will have unique values ββfor the entire table, in addition, this column must be selected in descending order. To do this, I combine the key fields with the separator character, otherwise two different lines can give the same result as (AB, C and A, BC).
So, I run the following query:
select country1||'_'||country2 from borders order by 1;
However, as a result, I see that the "_" character is excluded from sorting. The results look like this:
?column?
You can see that the result is sorted as if `_ 'did not exist in the lines.
If I use the letter (say, "x") as a separator, the order is correct. But I have to use a special character that does not appear in the country1 and country2 fields to avoid claims.
What should I do to take into account the symbol "_" during sorting.
EDIT
It turned out that concatenation has nothing to do with the problem. The problem is that the order simply ignores the "_" character.