Re: Which record causes referential integrity violation on delete

From: Dawid Kuroczko <qnex42(at)gmail(dot)com>
To: Andrus <noeetasoftspam(at)online(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Which record causes referential integrity violation on delete
Date: 2005-07-02 17:07:40
Message-ID: 758d5e7f05070210071c9e3dbe@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 7/2/05, Dawid Kuroczko <qnex42(at)gmail(dot)com> wrote:
> On 7/1/05, Andrus <noeetasoftspam(at)online(dot)ee> wrote:
> > In Postgres 8 I tried commad
> >
> > DELETE FROM customer WHERE id=123
> >
> > but got an error
> >
> > ERROR: update or delete on "customer" violates foreign key constraint
> > "invoice_customer_fkey" on "invoice"'
> >
> > How to determine the primary key of invoice table which causes this error
> > in generic way ?
>
> Well, I am not sure, but information you want may be contained in
> information_schema.key_column_usage and
> information_schema.referential_constraints
>
[,,,]

I forgot to add, this is of course a "simplistic" approach which:
1. may be simply wrong
2. assumes data is available to user in nformation_schema (I guess the
information schema lists only data owned by user; yet I am not sure
about that).
3. assumes foreign keys have really simple set up (no FKs depending on
FKs depending on FKs...)
4. and so on.

In other words, best approach would be "know thy schema" in the
application. ;)))

Regards,
Dawid

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2005-07-02 18:31:06 Re: Hot to restrict access to subset of data
Previous Message Dawid Kuroczko 2005-07-02 17:01:44 Re: Which record causes referential integrity violation on delete