I have a db in PostgreSQL 9.0, which has a table with a string field to store client codes.
These codes are alphanumeric and can start with a letter or number, for example 1, 2, A0001-4, A0001-2, 10
I want to order numeric first and then order by string, like
1, 2, 10, A0001-2, A0001-4
I do this with to_number(fields, '99999999')
, for example:
SELECT * FROM empleados ORDER BY to_number(legajo, '99999999'), legajo
But when the code is like 've'
, with no number, the query fails.
What can I do?