How to concatenate columns in a Postgres SELECT?

后端 未结 8 1685
醉酒成梦
醉酒成梦 2020-11-27 13:31

I have two string columns a and b in a table foo.

select a, b from foo returns values a and b<

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 13:58

    it is better to use CONCAT function in PostgreSQL for concatenation

    eg : select CONCAT(first_name,last_name) from person where pid = 136

    if you are using column_a || ' ' || column_b for concatenation for 2 column , if any of the value in column_a or column_b is null query will return null value. which may not be preferred in all cases.. so instead of this

    ||

    use

    CONCAT

    it will return relevant value if either of them have value

提交回复
热议问题