aquamad96
aquamad96

Reputation: 63

Incorrect ORDER BY PostgreSQL

I'm having a weird problem when I'm trying to order my column. The column is different than usual tables I'm working with where the43 is usually a comma in the numbers. Here the numbers have no comma and when I order the column I get something like

company_id
10097
1024
10304
151

Any help? Ideally I'd like to turn these numbers into numbers with commas so it's consistent with other tables when I do joins later

Upvotes: 1

Views: 850

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269603

Presumably, the values are strings. You can sort them in one of two ways. The first is the "string" way:

 order by length(company_id), company_id

The second is to convert to a number:

order by company_id::numeric

Upvotes: 4

Related Questions