找到违反要添加的约束的行

Find the row violating the constraint to be added

我正在尝试向 table 添加检查约束,例如

ALTER TABLE foo ADD CONSTRAINT bar CHECK (...);

我收到错误:

ERROR:  check constraint "bar" is violated by some row
********** Error **********

ERROR: check constraint "bar" is violated by some row
SQL state: 23514

有没有办法让 postgres (9.6) 告诉我它在哪一行失败了?会有很大帮助。

当然有。

Select * from bar where NOT <desired check constraint>;