1
I’m having a problem sorting columns in Postgresql despite being configured correctly in UTF-8.
The version of Postgresql is 9.3 and it is installing on a Macosx Maverick 10.9.5 (this problem has already occurred in previous versions of the system).
When I order the 'name' column in phpPgAdmin, Django or by the terminal, Postgresql is not dealing with upper, lower and lower case characters and accents correctly.
See the sorted table as it is getting:
As you can see, lowercase characters are getting after uppercase characters, and accented characters are getting last.
I want that regardless of having accents, be capitalized or lowercase, that the ordering is performed correctly. Someone knows how to solve this?
It’s not exactly a solution, but try sorting by
lower(nome)
(which is basically what a CITEXT column does automatically).– Bacco
Have you tried to explicitly in the comparison query? Type
select * from tabela order by nome collate "pt_BR";
Or maybe this combined with thelower(nome)
. I do not know if it will work, because I have read an ordination that at the same time respects accents and ignores capitalization is problematic, but here is the suggestion...– mgibsonbr
@Bacco the problem is that just this is not enough, I really wanted to change some Postgresql configuration to return the way I want without the need for this.
– Paulo
@mgibsonbr the last time I had this problem I was obliged to create a new column for each field that needed sorting and filter, these new columns being treated to not have accents and uppercase characters, so I change the order of the treated column, but I show you the result of the original column. Due to the system resources and number of tables, this type of query is unviable as you suggested. The way out will be for me to resort to what I used to do.
– Paulo
For instance, which column collation name ?
– gmsantos
use citext reference at link :http://simplesideias.com.br/usando-campos-case-insensitive-no-postgresql
– Pedro Rangel
@gmsantos the table is being generated by Django, and the bank is set to
lc_collate pt_BR.UTF-8
– Paulo
@Bacco but just leave it tiny is not enough, I need that in reading do not distinguish when there are accents, so I am being obliged to have two columns 'name' and 'sort_name', and in the first the original text is saved and in the second the text without accents and lowercase. In this way it works perfectly, when seeking words without placing accent, returns also those who have accent. The only problem is the duplicate content only to work correctly the ordering and the search.
– Paulo
@Bacco remember that with mysql did not have this problem, the issue is that it is impossible to change table by table, even because they are created dynamically and at any time can be recreated/changed, outside when it is run tests and I have no control over it.
– Paulo
@Orion posted a test in SQL Fiddle with collation no 9.3 and apparently was in order.
– Bacco