本文介绍了如何串联Postgres SELECT中的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表foo
中有两个字符串列a
和b
.
I have two string columns a
and b
in a table foo
.
select a, b from foo
返回值a
和b
.但是,a
和b
的串联不起作用.我试过了:
select a, b from foo
returns values a
and b
. However, concatenation of a
and b
does not work. I tried :
select a || b from foo
和
select a||', '||b from foo
根据评论更新:两列均为character(2)
类型.
Update from comments: both columns are type character(2)
.
推荐答案
问题出在值中为null.则串联不能与null一起使用.解决方法如下:
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;
这篇关于如何串联Postgres SELECT中的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!