如何从 table 列中删除空值?

How do I remove null from table columns?

我有一个数据库 table,其中填充了 10k 行数据。这些行中有很多在特定列中具有空值。如何用例如字符串列的空字符串替换此空值?

我正在寻找最简单的方法来执行此操作,因为此操作只需要执行一次一次

我试过的:

UPDATE tablename set mycolumn='' where mycolumn is null;

这给了我以下错误:

Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.

我不是数据库的管理员,所以我不能禁用安全模式。

UPDATE tablename set mycolumn=''
  where Id in (SELECT Id FROM tablename where mycolumn is null);

这给了我以下错误:

Error Code: 1093. You can't specify target table 'tablename' for update in FROM clause.


注:

在上面的示例中,我用占位符替换了真实的 tablename 和 column-name。

您可以更改 table 并为列设置 NOT NULL。

您还可以简单地执行以下操作:

To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.

嗯,你可以这样做:

 UPDATE tablename set mycolumn='' where mycolumn is null and Id is not null;

这实际上并没有改变更新逻辑中的任何内容(因为 ID 是主键并且不能为空)并且它在 where 子句中使用键列。

你可以试试

UPDATE tablename set mycolumn = '' 
where Id IN (select Id from (select Id from tablename where mycolumn IS NULL) as x)

但为什么要用空字符串替换 NULL 值?

如果您可以禁用安全模式 this 将是重复的。