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 BD2E4D1C4E1 for ; Sat, 9 Aug 2003 21:44:55 +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 06356-10 for ; Sat, 9 Aug 2003 18:43:26 -0300 (ADT) Received: from ua.fm (unknown [195.248.176.188]) by svr1.postgresql.org (Postfix) with ESMTP id 1748ED1C939 for ; Sat, 9 Aug 2003 18:44:43 -0300 (ADT) Received: from [212.86.230.70] (account evl HELO evl) by ua.fm (CommuniGate Pro SMTP 3.5.9) with ESMTP id 34477740; Sun, 10 Aug 2003 00:44:41 +0300 Date: Sun, 10 Aug 2003 00:44:32 +0300 From: eVl One X-Mailer: FC'2000! (v1.61) UNREG / CD5BF9353B3B7091 Reply-To: eVl One Organization: eVl inc. X-Priority: 3 (Normal) Message-ID: <18618711976.20030810004432@my-mail.com.ua> To: Bruno Wolff III Cc: pgsql-sql@postgresql.org Subject: Re: How to check: is some key referenced from sometable In-Reply-To: <20030809150809.GA22927@wolff.to> References: <3159.195.5.48.107.1059985076.squirrel@my-mail.com.ua> <20030809150809.GA22927@wolff.to> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/88 X-Sequence-Number: 14704 Hello, Bruno. You wrote 9 08 2003, 18:08:09: BWI> On Mon, Aug 04, 2003 at 11:17:56 +0300, BWI> evl@my-mail.com.ua wrote: >> Please help. >> >> Need a boolean function which returns true if given key in table is >> referensed from another table(s). BWI> Use "exists" with a subselect. Something like: BWI> select exists(select 1 from table where table.key = 'value'); Thanx for advice, but way I know and it can't be used. That's why I've got too many and/or too big tables from which such key is referenced. I mean (in some simplified way): table A ( -- main table A id SERIAL, PRIMARY KEY(id) ); tableBxx ( -- a lot of tables which got a.id as FOREIGN KEY ... -- too much to check 'em all with EXISTS queries a_id int4 REFERENCES a(id), -- without significant perfomance loss ... ); 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. -- Best regards, eVl