简体   繁体   English

在预填充列上生成 null 违规的更新语句

[英]Update statement generating null violations on pre-populated column

I'm trying to update rows in PostgreSQL DB.我正在尝试更新 PostgreSQL DB 中的行。 When I try to run an update query to update values in 2 columns (with no constraints).当我尝试运行更新查询以更新 2 列中的值时(没有约束)。 My table structure is as follows (variable names changed)我的表结构如下(变量名改了)

schema.table架构表
|-> id (not null) |-> id(非空)
|-> company (varchar) |-> 公司 (varchar)
|-> model |-> model
|-> serial_number |-> 序列号
|-> series |-> 系列

There is unique constraint on model and serial_number. model 和序列号有唯一的约束。

UPDATE schema.table 
SET company = 'Apple' WHERE model like 'iPhone%' AND series like 'X%';

The above snippet generates the following error even when the row already has a serial_number.即使该行已经有一个序列号,上面的代码片段也会产生以下错误。

Reason:
SQL Error [23502]: ERROR: null value in column "serial_number" violates not-null constraint

I'd like to set company to "Apple" were model='iPhone' and series is like 'X%'.我想将公司设置为“Apple”,型号='iPhone',系列就像'X%'。

This code:这段代码:

UPDATE schema.table 
    SET company = 'Apple'
    WHERE model like 'iPhone%' AND series like 'X%';

Does not change the serial_number at all.根本不更改serial_number号。 Hence, I conclude that you have an update trigger on the table that is causing the problem.因此,我得出结论,您在导致问题的表上有一个update触发器。 So, look into any triggers that are there.因此,请查看那里的任何触发器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM