Append text to column data based on the column in PostgreSQL

前端 未结 2 1471
生来不讨喜
生来不讨喜 2021-02-02 06:33

I would like to append some text to every cell in each column of my table to act as a symbol for that particular column. For example say my table is as follows (all fields are t

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 06:45

    The accepted answer is not handle null value and blank space. So I gave this answer. If it help someone, it will be my pleasure.

    update "public"."mytable" set 
    "name"= case when "name" is null or trim("name")='' then null else 'a' || "name" end,
    "age"= case when "age" is null or trim("age")='' then null else 'b' || "age" end,
    "location"= case when "location" is null or trim("location")='' then null else 'c' || "location" end;
    

提交回复
热议问题