Search code examples
sqlpostgresqltrim

Trim all occurences of a character in PostgreSql


I am trying to remove all the zeros from the values of the attribute salary. I am using TRIM function (by typecasting salary into TEXT). TRIM function does not remove 0s that are in between, for example, if I use it on 809800 the result is '8098'. The '0' in the middle is still there. Here is what I am doing:

PostgreSql

Thanks in advance.


Solution

  • Use replace() for that:

    demo:db<>fiddle

    SELECT replace('01000200330004000', '0', '')
    

    or for using with your salary column:

    SELECT replace(salary, '0', '')