当我做这样的选择时
select
replace(replace(t.field,'{0}',t.parameter01), '{1}', t.parameter02)
from table t
即使 t.field 包含没有任何占位符的文本,我也会得到一个空结果。有人可以解释为什么会这样吗?
最佳答案
我已经想通了。如果 replace 函数的第三个参数为 null,尽管第二个参数与第一个参数中的任何内容都不匹配,但结果将为 null。解决方法是替换第三个参数的值(如果它为 null):
select
replace(t.field, t.parameter01, coalesce(t.parameter02, ''))
from table t
关于sql - Postgresql 替换函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27186413/