如果列的初始值为null,则将文本追加到PostgreSQL中的列数据。它的价值不变。
尚不清楚您要实现的目标,但是:
如果该列的值为,则null
您不能对其“附加”一个值,因为任何涉及到的表达式都将null
产生null(null||'foo'
is null
)。在这种情况下,您只需将空值替换为新值即可:
update the_table
set the_column = 'new value'
where the_column is null;
如果“初始值是null ”是指“当前值是一个空字符串”,那么您将执行以下操作:
update the_table
set the_column = the_column || 'this will be appended'
where the_column = '';
等同于:
update the_table
set the_column = 'this will be appended'
where the_column = '';
null
而且''
是不同的东西
另一种选择是使用该concat()
函数,该函数会将null
值隐式视为空字符串:
update the_table
set the_column = concat(the_column, 'this will be appended')
where ...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句