当我运行以下SQL代码时:
INSERT INTO table
(column1, column1)
SELECT column1, column2
FROM other_table
WHERE column2 = 'foo'
ON CONFLICT DO NOTHING;
我知道
PG::CheckViolation: ERROR:
new row for relation "table" violates
check constraint "tables_column1_valid_first_char"
如何跳过违反该检查约束的行?
我尝试过
INSERT INTO table
(column1, column1)
SELECT column1, column2
FROM other_table
WHERE column2 = 'foo'
ON CONFLICT ON CONSTRAINT tables_column1_valid_first_char DO NOTHING;
但是失败了>>
PG::WrongObjectType: ERROR: constraint in ON CONFLICT clause has no associated index
该约束如下:
ADD CONSTRAINT tables_column1_valid_first_char
CHECK (SUBSTRING(text, 1,1) ~* '^[a-zàâçéèêëîïôûùüÿæœ]');
当我运行以下SQL代码时:INSERT INTO表(column1,column1)SELECT column1,column2 FROM other_table WHERE column2 ='foo'ON CONFLICT DO NOTHING;我得到PG :: CheckViolation:错误:新...
ON CONFLICT
仅处理唯一约束,不适用于检查约束(或外键约束)。