【发布时间】:2018-10-23 23:47:24
【问题描述】:
我对学习合并感到困惑,我是 sql 新手。
示例:
select case when value is null then 1
else value end as value
from table
和
select coalesce(value, 1)
from table
在我在互联网上看到的教程中有类似
select coalesce (arg_1, arg_2, arg_3)
如果我做
select coalesce(value, 1, 2)
我怎样才能显示返回值为 2?
【问题讨论】:
-
Postgresql docs 清楚地解释了该函数的工作原理。当您不了解函数的工作原理时,这是一个很好的起点。
The COALESCE function returns the first of its arguments that is not null. -
Coalesce返回它匹配的第一个非空值。所以在你的最后一种情况下,1不为空,所以如果value为空并且2永远无法返回,它将被返回。
标签: sql postgresql