wylasr
wylasr

Reputation: 117

how to format character as specify length in postgresql

In my database ,I have two record in a table, one's value is "201612" ,the other one is "20171" ,how to get "201701" when I query this table ? thanks

Upvotes: 0

Views: 42

Answers (1)

Gurwinder Singh
Gurwinder Singh

Reputation: 39467

Something like this maybe:

select 
    case when col > 99999 then col
        else 100 * (col / 10) + (col % 10)
    end as col
from your_table;

Demo

Upvotes: 1

Related Questions