Search code examples
postgresqltrailing

Remove trailing '.0' only postgresql


I am removing part of a string in my column customer_id in Postgresql.

Customer_id : 

N12300 
245007.00 


UPDATE public.meltuniverse SET customer_id=trim(trailing '.0' FROM customer_id::varchar);

I only want to remove the .00 at the end and now it returns me :

N123
245007 

How i can fix this?


Solution

  • Use Regular Expressions:

    UPDATE public.meltuniverse 
    SET customer_id = regexp_replace(customer_id, '\.00$', '')
    

    The pattern '\.00$' matches exact substring '.00' at the end of the string.

    Db<>fiddle.