[英]Cannot insert a NULL value into column x using update statement in Redshift
I am trying to update several rows using output of the other query, having the condition when nombregestorevento LIKE 'karate%'.我正在尝试使用其他查询的 output 更新多行,条件是 nombregestorevento LIKE 'karate%'。 However I don't understand the reason why Redshift is throwing the error ERROR: Cannot insert a NULL value into column nombregestorevento while there is not any null in the output of any of the queries.
但是我不明白 Redshift 抛出错误错误的原因:无法将 NULL 值插入列 nombregestorevento而在任何查询的 output 中都没有任何 null。
Here is the query:这是查询:
begin;
update lu_gestor_evento
set nombregestorevento = (select nombregestorevento from lu_gestor_evento_pro a12
where a12.id_gestorevento = lu_gestor_evento.id_gestorevento)
WHERE lu_gestor_evento.nombregestorevento LIKE 'karate%';
commit;
I had checked both tables and I can't find any Null in any of the tables.我检查了两个表,但在任何一个表中都找不到任何 Null。 How can I change the query to not throwing this error.
如何更改查询以不引发此错误。
The error does indicate that your subquery returns a null
value.该错误确实表明您的子查询返回了
null
值。 If there are no null
values in the source table, then it means that the subquery returned no rows - which reads as a null
value in the set
clause.如果源表中没有
null
值,则意味着子查询未返回任何行- 在set
子句中读取为null
值。
In other words, the error happens when the id_gestorevento
of target table lu_gestor_evento
does not exist in source table lu_gestor_evento_pro
.换句话说,当源表
lu_gestor_evento_pro
中不存在目标表lu_gestor_evento
的id_gestorevento
时,就会发生错误。
Probably, you want to update matching rows only, and leave others untouched.可能您只想更新匹配的行,而其他行保持不变。 If so, in Redshift we can use the
update/from
syntax:如果是这样,在 Redshift 中我们可以使用
update/from
语法:
update lu_gestor_evento e
set nombregestorevento = ep.nombregestorevento
from lu_gestor_evento_pro ep
where ep.id_gestorevento = e.id_gestorevento
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.