I’m trying to update rows in PostgreSQL DB. When I try to run an update query to update values in 2 columns (with no constraints). My table structure is as follows (variable names changed)
schema.table
|-> id (not null)
|-> company (varchar)
|-> model
|-> serial_number
|-> series
There is unique constraint on model and serial_number.
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%’.
Advertisement
Answer
This code:
UPDATE schema.table SET company = 'Apple' WHERE model like 'iPhone%' AND series like 'X%';
Does not change the serial_number
at all. Hence, I conclude that you have an update
trigger on the table that is causing the problem. So, look into any triggers that are there.