2

I would like to order a bpchar column in the following order (first order by a-z, then numbers):

abc
bcd     
xrf/1     
zyd   
0/abc
0/bdc   
0/efg    

How could I accomplish that?

Thank you

1 Answer 1

6

Can't fully tell from your question what you actually want. If it is the first character of the string you want to check whether it's numeric or alphabet, you may use a CASE expression in ORDER BY like this.

select * FROM t ORDER BY
          CASE 
             WHEN col ~ '^[a-zA-Z]' THEN 1
             WHEN col ~ '^[0-9]'    THEN 2
           END,col;

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.