如果列初始值为null,则将文本附加到PostgreSQL中的列数据.它没有改变价值.
目前还不清楚你想要实现的目标,但是:
如果列的值是null,则无法向其"追加"值,因为任何涉及nullyield的表达式为null(null||'foo'is null).在这种情况下,您只需将null值替换为新值:
update the_table
set the_column = 'new value'
where the_column is null;
Run Code Online (Sandbox Code Playgroud)
如果" 初始值为空 "意味着" 当前值是否为空字符串 ",那么您将执行以下操作:
update the_table
set the_column = the_column || 'this will be appended'
where the_column = '';
Run Code Online (Sandbox Code Playgroud)
这与:
update the_table
set the_column = 'this will be appended'
where the_column = '';
Run Code Online (Sandbox Code Playgroud)
null并且''是不同的事情
另一种选择是使用concat()将隐式将null值视为空字符串的函数:
update the_table
set the_column = concat(the_column, 'this will be appended')
where ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3768 次 |
| 最近记录: |