X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id B832CD1C47A for ; Tue, 12 Aug 2003 16:47:17 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 83523-04 for ; Tue, 12 Aug 2003 13:45:44 -0300 (ADT) Received: from irko.smoothcorp.com (unknown [208.49.241.41]) by svr1.postgresql.org (Postfix) with ESMTP id AC2A2D1B561 for ; Tue, 12 Aug 2003 13:47:06 -0300 (ADT) Received: from [10.0.1.63] (helo=jgardner.smoothcorp.com) by irko.smoothcorp.com with esmtp (Exim 4.12) id 19mcIX-0002yS-00; Tue, 12 Aug 2003 09:47:01 -0700 Received: from jgardner.smoothcorp.com (localhost.localdomain [127.0.0.1]) by jgardner.smoothcorp.com (8.12.8/8.12.8) with ESMTP id h7CGl2sN022216; Tue, 12 Aug 2003 09:47:02 -0700 Received: from localhost (localhost [[UNIX: localhost]]) by jgardner.smoothcorp.com (8.12.8/8.12.8/Submit) id h7CGkuaS022209; Tue, 12 Aug 2003 09:46:56 -0700 From: Jonathan Gardner To: eVl One , Bruno Wolff III Subject: Re: How to check: is some key referenced from sometable Date: Tue, 12 Aug 2003 09:46:54 -0700 User-Agent: KMail/1.5 Cc: pgsql-sql@postgresql.org References: <3159.195.5.48.107.1059985076.squirrel@my-mail.com.ua> <20030809150809.GA22927@wolff.to> <18618711976.20030810004432@my-mail.com.ua> In-Reply-To: <18618711976.20030810004432@my-mail.com.ua> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Description: clearsigned data Content-Disposition: inline Message-Id: <200308120946.56006.jgardner@jonathangardner.net> X-SA-Exim-Rcpt-To: evl@my-mail.com.ua, bruno@wolff.to, pgsql-sql@postgresql.org X-SA-Exim-Scanned: No; SAEximRunCond expanded to false X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/118 X-Sequence-Number: 14734 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday 09 August 2003 14:44, eVl One wrote: > So I need: > "silent delete" - i.e. when trying to DELETE row from A I'll not > fall out with "$1 referential integrity violation - key in A still > referenced from Bxx", but silently doesn't delete row ('cause run it > from function and need function to executes farther after delete); > "something to check reference" - system (potgresql) is very quickly > realizes that key is referenced from another table, maybe this > information may be accessed through some system relations, or so? > Thanx for attention. You may want to check out the "ON DELETE" and "ON UPDATE" clauses of the=20 FOREIGN KEY syntax. This will help you keep you data consistent. Otherwise, if you want to know what is referencing something, you'll=20 have to query all of those tables. Your database structure should be=20 well-defined and thought out, so you should be able to figure out what=20 all is referencing it. If you need it for day-to-day queries, you may=20 want to rethink your design. If you like, take a look at the pg_trigger table. The way PostgreSQL=20 manages the foreign key references is through triggers. You may be able=20 to identify which triggers are which, and from there, determine which=20 tables are referencing which tables. - --=20 Jonathan Gardner Live Free, Use Linux! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE/ORn/WgwF3QvpWNwRAsJ5AJ9iGmopncQsyizb6yIh2CvCQsSmwQCg0UZ/ xImGLW35bdAJSuzCWc7yxBU=3D =3DeQGH -----END PGP SIGNATURE-----