pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Poole <rp@guests.deus.net>
To: pgsql-general@postgresql.org
Subject: Re: [SQL] simple addition of constraints problem
Date: Tue, 8 Jun 2004 23:55:51 +0100
Message-ID: <20040608225550.GA26592@guests.deus.net> (raw)
In-Reply-To: <p0602040bbcebe1496b26@[66.152.196.53]>
References: <p0602040bbcebe1496b26@[66.152.196.53]>

On Tue, Jun 08, 2004 at 05:51:22PM -0400, Michelle Murrain wrote:

> I'd like to make 'courseid' in this second table a foreign key, 
> referencing 'courseid' in the first table. So I did this command:
> 
> charter_dev2=# ALTER TABLE coursesevaluations ADD CONSTRAINT rc_ce 
> FOREIGN KEY (courseid) REFERENCES rcourseinfo (courseid);
> 
> And I get this result:
> 
> NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY 
> check(s)
> ERROR:  rc_ce referential integrity violation - key referenced from 
> coursesevaluations not found in rcourseinfo

What this is telling you is not that there is any problem with your
formulation of the constraint (which as far as I can tell is what you
want), but that the existing data in the tables violates the constraint
you're trying to impose. If you do something like

SELECT rcoursesevaluations.courseid
FROM rcoursesevalutations NATURAL LEFT JOIN rcourseinfo
WHERE rcourseinfo.courseid IS NULL

you should see which courseids appear in rcoursesevaluations but not in
rcourseinfo.


Richard



view thread (3+ messages)  latest in thread

Message-ID: <20040608225550.GA26592@guests.deus.net>
Permalink:  ../20040608225550.GA26592@guests.deus.net/
Also on:    postgresql.org/message-id/20040608225550.GA26592@guests.deus.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rp@guests.deus.net, pgsql-general@postgresql.org
  Subject: Re: [SQL] simple addition of constraints problem
  In-Reply-To: <20040608225550.GA26592@guests.deus.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox