How do I remove all spaces from a field in a Postgres database in an update query?

前端 未结 7 1601
梦毁少年i
梦毁少年i 2020-12-30 18:58

What would be the proper syntax used to run an update query on a table to remove all spaces from the values in a column?

My table is called users and in

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-30 19:51

    You can include a condition to update only values that need it with the replace.

    UPDATE users SET fullname = REPLACE(fullname, ' ', '') WHERE fullname ~* ' ';
    

    Quick and dirty

提交回复
热议问题