From: | "Keith Worthington" <keithw(at)narrowpathinc(dot)com> |
---|---|
To: | Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> |
Cc: | PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: finding data violating constraint |
Date: | 2004-10-19 16:33:42 |
Message-ID: | 20041019163342.M80980@narrowpathinc.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
> On Tue, 19 Oct 2004, Keith Worthington wrote:
>
> > I am trying to build a foreign key constraint. The
> > objective is to prevent parts from being entered that
> > do not have a valid sales account. When I try to
> > build the constraint it fails telling me that there
> > is a violation. I have looked at the data and just
> > can't seem to find the problem. Is there a way to
> > find the data that is causing the problem? I tried
> > deleting all the data and building the constraint.
> > That of course works but then I am unable to load
> > the data and I have no better idea of where the
> > problem is located.
>
> What version are you using? IIRC, 7.4 should give at least the first
> failing row in the error message.
>
> In general you can use something like:
>
> select * from referencing_table left outer join referenced_table on
> (referencing_table.referencing_col = referenced_table.referenced_col)
> where referenced_table.referenced_col is null;
>
> to find unsatisfied constraint values. If the constraint has
> multiple columns, you can add AND ... conditions inside the on
> clause (but the where clause should be fine with just one column).
>
Stephan,
That query is exactly what I needed. I ran it and out popped the two
offending records. They had no values in a column that does not allow null!
Now I have to figure out what copy is doing that I end up with that condition.
}:-| Thanks for the help.
BTW I am running PostgreSQL 7.3.6 with pgAdmin3 v1.0.2 on RedHat Enterprise
Linux v3. I am going to investigate upgrading to at least 7.4.5. Maybe even
8.0 Beta3 since the system is under development anyway.
Kind Regards,
Keith
______________________________________________
99main Internet Services http://www.99main.com
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Guerin | 2004-10-19 17:08:29 | Vacuum is looping on tables? |
Previous Message | Tom Lane | 2004-10-19 14:57:41 | Re: finding data violating constraint |