WITH empleados(legajo) AS (
VALUES
('A0001-4'::text)
,('123.345-56')
,('ve')
,('123')
,('123 ve')
)
SELECT *
FROM empleados
ORDER BY CASE WHEN legajo ~ '\D' THEN 1000000000::int
ELSE to_number(legajo, '999999999')::int END
,legajo;
~
is the regular expression operaor.
\D
is the classs shorthand for non-digits.
Rows with non-digit characters in legajo (legajo ~ '\D'
) come later.
Never use SIMILAR TO
, it's an utterly pointless operator.