Re: BUG #5205: Cannot ADD CONSTRAINT ... FOREIGN KEY...

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Alain Baeckeroot <alain(dot)baeckeroot(at)laposte(dot)net>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5205: Cannot ADD CONSTRAINT ... FOREIGN KEY...
Date: 2009-11-23 04:37:09
Message-ID: 603c8f070911222037v18aa8437l39e70328fff9b56f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Nov 20, 2009 at 6:44 PM, Alain Baeckeroot
<alain(dot)baeckeroot(at)laposte(dot)net> wrote:
>
> The following bug has been logged online:
>
> Bug reference:      5205
> Logged by:          Alain Baeckeroot
> Email address:      alain(dot)baeckeroot(at)laposte(dot)net
> PostgreSQL version: 8.4.1
> Operating system:   Linux (Ubuntu 9.10)
> Description:        Cannot ADD CONSTRAINT ... FOREIGN KEY...
> Details:
>
> I think i could add this constraint on an existing table:
> => select id from asset except (select asset.id from asset, base where
> asset.id_base = base.id);
>  id
> ----
> (0 rows)
>
> => ALTER TABLE ONLY asset ADD CONSTRAINT asset_id_base_fkey FOREIGN KEY
> (id_base) REFERENCES base(id);
> ERREUR:  une instruction insert ou update sur la table « asset » viole la
> contrainte de clé
> étrangère « asset_id_base_fkey »
> DETAIL:  La clé (id_base)=(196) n'est pas présente dans la table « base
> ».
>
> => select * from base where id = 196;
>  id  |         date_crea          |         date_modif         | auth_crea |
> auth_modif | ordre
> -----+----------------------------+----------------------------+-----------+
> ------------+-------
>  196 | 2009-03-16 11:57:44.391607 | 2009-03-16 11:57:44.391607 | sql       |
> sql        |     7
> (1 row)
>
> What is wrong ?
> The table asset inherits from base, but it seems to be allowed and to work
> (at least on the dumb test i did)

I am guessing that the row may be in an inherited child of base rather
than in base itself?

...Robert

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Maithili 2009-11-23 08:34:32 BUG #5209: error in intidb process when installing on japanese machine which is in japanese domain
Previous Message Robert Haas 2009-11-23 04:35:12 Re: BUG #5202: Rule affecting more than one row is only fired once with LIMIT 1