如果列初始值为null,则将文本附加到PostgreSQL中的列数据

Suf*_*lek -1 postgresql

如果列初始值为null,则将文本附加到PostgreSQL中的列数据.它没有改变价值.

a_h*_*ame 9

目前还不清楚你想要实现的目标,但是:

如果列的值是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)

  • @SamiKuhmonen:你是对的。我只是想澄清一下,附加到“null”值将不会按预期工作。 (2认同)