Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 117139FB6B7 for ; Tue, 15 May 2007 22:38:18 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 11829-10 for ; Tue, 15 May 2007 22:38:01 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id EDB189FB6A6 for ; Tue, 15 May 2007 22:38:12 -0300 (ADT) Received: by noel.decibel.org (Postfix, from userid 1001) id 4484E564D5; Tue, 15 May 2007 20:38:11 -0500 (CDT) Received: (hashcash-sendmail, from uid 1001); Tue, 15 May 2007 20:38:09 -0500 Date: Tue, 15 May 2007 20:38:09 -0500 From: "Jim C. Nasby" To: Peter Hanson Cc: pgsql-sql@postgresql.org Subject: Re: Adding "on delete cascade" to all foreign key constraints Message-ID: <20070516013809.GH11533@nasby.net> References: <200705151219.54324.lists@pkhanson.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200705151219.54324.lists@pkhanson.com> X-Operating-System: FreeBSD 6.1-RELEASE-p10 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.13 (2006-08-11) X-Hashcash: 1:20:070516:lists@pkhanson.com::opzFaYprYXoo4lEM:0000000000000000000 0000000000000000000000004BjL X-Hashcash: 1:20:070516:pgsql-sql@postgresql.org::52q0wB/iIN8FrP7s:0000000000000 0000000000000000000000000jMc X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/135 X-Sequence-Number: 28415 On Tue, May 15, 2007 at 12:19:54PM -0500, Peter Hanson wrote: > Hello, > > I was wondering if there's a fast way I can add "on delete cascade" to all > foreign key constraints in my database? Maybe a quick update I can make > against the catalog possibly? Or is there a way I can query for all foreign > key constrains in the database and then I could write up a quick script to do > the updates for me. You shouldn't go mucking about with the system tables unless absolutely necessary. Instead, write a SELECT that outputs the appropriate syntax. You could do that by querying the catalogs directly, but I think you'll find the pg_user_foreign_keys view defined by http://pgfoundry.org/projects/newsysviews to be most helpful. -- Jim Nasby decibel@decibel.org EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)