ERROR: check constraint - PostgreSQL 9.2

From: "drum(dot)lucas(at)gmail(dot)com" <drum(dot)lucas(at)gmail(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: ERROR: check constraint - PostgreSQL 9.2
Date: 2016-01-25 04:12:23
Message-ID: CAE_gQfXTns1FR5Fx9wxpo1oZYwat639ua-gAqWZyNg201HCU=Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all, need some help to add a constraint to an existing table (with data).

I'm running the command:

*Query:*

ALTER TABLE integrations.accounts DROP CONSTRAINT IF EXISTS
cc_at_least_one_setting_needed,
ADD CONSTRAINT cc_at_least_one_setting_needed CHECK
(("qb_settings" IS NOT NULL) or

("xero_settings" IS NOT NULL) or

("freshbooks_settings" IS NOT NULL) or

("myob_settings" IS NOT NULL) or

("ppy_settings" IS NOT NULL));

But, I got the following error:

ERROR: check constraint "cc_at_least_one_setting_needed" is violated by
> some row

So, I made a SELECT to get some data, to see where's the issue:

SELECT * FROM integrations.accounts WHERE qb_settings IS NULL OR
xero_settings IS NULL OR freshbooks_settings IS NULL OR myob_settings
IS NULL OR ppy_settings IS NULL;

And I got 59 rows. So, it seems that's my problem - I have NULLS that
violate the CHECK CONSTRAINT.

*Question:*
How can I solve the problem? How can I get the command successfully be done?

Cheers;
Lucas Possamai

- kinghost.co.nz
<http://forum.kinghost.co.nz/memberlist.php?mode=viewprofile&u=2&sid=e999f8370385657a65d41d5ff60b0b38>
- DigitalOcean <https://m.do.co/c/a0d31c597a03>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua Berkus 2016-01-25 04:14:07 Re: A motion
Previous Message Tom Smith 2016-01-25 04:09:43 TABLESAMPLE usage