Postgresql Sort Text Column As Integer
1 min readAug 29, 2018
Hi all. This article about sorting text or varchar column as integer. If you want to do this with default order by command, result is not what you want. Default text type column sorting works as alphabetical order and text length. And this article shows you, how you can handle with this.
Code
select xColumn from (select distinct xColumn from xTable where type = ‘xx’) order by cast(xColumn as integer)
How
This code line recieves xColumn from xTable and sorts as integer value.