Search code examples
postgresqlsql-order-bycase-sensitive

How to sort the results in case sensitive manner in PostgreSQL?


I have a table with utf-8 strings in PostgresQL. When I add ORDER BY to a SELECT query, the results are ordered in case-insensitive manner, which seems odd:

AA
ab
ac
Am
At

How can I sort the results case-sensitively, i.e.

AA
Am
At
ab
ac

Solution

  • You could be converting as BYTEA

    select  your_column 
    from your_table  
    order by  your_column::TEXT::BYTEA