Skip site navigation (1) Skip section navigation (2)

possible to DELETE CASCADE?

From: Miles Keaton <mileskeaton(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: possible to DELETE CASCADE?
Date: 2004-12-30 19:10:38
Message-ID: 59b2d39b04123011101872498d@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
Is it possible for a query to delete a record and all of its
foreign-key dependents?

I see DROP CASCADE, but not a DELETE CASCADE.

What I'm trying to do:
I have a "clients" table.
I have many different tables that use the clients.id as a foreign key.
When I delete a client, I want it to delete all records in those many
different tables that reference this client.

Right now I have my script passing many queries to delete them
individually.  ("delete from history where client_id=?; delete from
payments where client_id=?" -- etc)

Any shortcut way to do this?

Responses

pgsql-general by date

Next:From: Thomas Braad ToftDate: 2004-12-30 19:28:16
Subject: Re: possible to DELETE CASCADE?
Previous:From: Scott MarloweDate: 2004-12-30 18:15:32
Subject: Re: pg_dump and pgpool

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group