foreign key constraints, cannot delete

From: Josh Close <narshe(at)gmail(dot)com>
To: POSTGRES <pgsql-general(at)postgresql(dot)org>
Subject: foreign key constraints, cannot delete
Date: 2004-10-08 21:07:43
Message-ID: 4a0cafe2041008140757d778b2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How can a delete rows from a table that has foreign key constraints?
Here is how I have it set up.

I have 2 tables, tableA has fields and id's and tableB has fields that
reference tableA's id's. I'm not able to do this

BEGIN TRANSACTION;

DELETE FROM tableB
WHERE tableAid = 5;

DELETE FROM tableA
WHERE id = 5;

COMMIT TRANSATION;

Even though I delete everything from tableB that references tableA, I
can't delete the field from tableA.

Is this because of the begin and commit? Do I need to commit after each delete?

The only problem with commiting after each is, if one fails for some
reason, I need it to rollback.

-Josh

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2004-10-08 21:15:24 Re: foreign key constraints, cannot delete
Previous Message Dominic Mitchell 2004-10-08 20:00:27 Re: CGI program cannot access database