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

前端 未结 7 1645
梦毁少年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

    If it's a text[] column, you can do something like this:

    UPDATE users SET pets = string_to_array(replace(array_to_string(pets, ';'), ' ', ''), ';');
    

    Before: {"Big Dog", "Small Cat"}

    After: {"BigDog", "SmallCat"}

提交回复
热议问题