ERROR: check constraint - PostgreSQL 9.2 - Mailing list pgsql-general

From drum.lucas@gmail.com
Subject ERROR: check constraint - PostgreSQL 9.2
Date
Msg-id CAE_gQfXTns1FR5Fx9wxpo1oZYwat639ua-gAqWZyNg201HCU=Q@mail.gmail.com
Whole thread Raw
Responses Re: ERROR: check constraint - PostgreSQL 9.2  (Christophe Pettus <xof@thebuild.com>)
Re: ERROR: check constraint - PostgreSQL 9.2  (Vick Khera <vivek@khera.org>)
List 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

pgsql-general by date:

Previous
From: Tom Smith
Date:
Subject: TABLESAMPLE usage
Next
From: Joshua Berkus
Date:
Subject: Re: A motion