I have two string columns a
and b
in a table foo
.
select a, b from foo
returns values a
and b<
The problem was in nulls in the values; then the concatenation does not work with nulls. The solution is as follows:
SELECT coalesce(a, '') || coalesce(b, '') FROM foo;
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