I have internal communication table that has a field called ci_num and it's format is number/year. ex: 23/2020.
I would like to order my table based in this field. I've searched but didn't find how to create a function to order this way.
In java, I do this using a custom sorting function. I've tried to do the same thing in postgres but without success.
using ascending:
select * from cis c order by ci_num asc
result:
ci_id|ci_num |tipo_cod|status_cod|setor_cod|usuario_id -----|-------|--------|----------|---------|---------- 10|10/2020|GE |EC |NUTEC | 1 11|11/2020|CO |DB |NUCAD | 4 1|1/2020 |CO |DE |NUCAD | 1 12|12/2020|CO |NG |NUTEC | 4 13|13/2020|CO |AT |NUOPE | 4 14|14/2020|CO |NG |NUTEC | 4 15|15/2020|GE |DE |NUOPE | 4 16|16/2020|CO |NG |NUTEC | 4 17|17/2020|CO |CA |NUTEC | 4
using descending gets worse:
select * from cis c order by ci_num desc
ci_id|ci_num |tipo_cod|status_cod|setor_cod|usuario_id -----|-------|--------|----------|---------|---------- 9|9/2020 |IN |AT |NUOPE | 4 8|8/2020 |CO |NG |NUTEC | 4 7|7/2020 |GE |CA |NUTEC | 4 6|6/2020 |HE |CR |NUCAD | 1 54|54/2020|GE |EA |NUTEC | 4 53|53/2020|GE |EA |NUOPE | 1 52|52/2020|GE |EA |NUOPE | 1
Thanks for your help!