foreign key constraints, cannot delete - Mailing list pgsql-general

From Josh Close
Subject foreign key constraints, cannot delete
Date
Msg-id 4a0cafe2041008140757d778b2@mail.gmail.com
Whole thread Raw
Responses Re: foreign key constraints, cannot delete  (Martijn van Oosterhout <kleptog@svana.org>)
List 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

pgsql-general by date:

Previous
From: dom@happygiraffe.net (Dominic Mitchell)
Date:
Subject: Re: CGI program cannot access database
Next
From: Martijn van Oosterhout
Date:
Subject: Re: foreign key constraints, cannot delete