X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 429AF11F6786 for ; Wed, 19 Apr 2006 14:24:05 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 2.799 X-Spam-Level: ** X-Spam-Status: No, score=2.799 required=5 tests=[DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44, DNS_FROM_RFC_WHOIS=0.879, UNPARSEABLE_RELAY=0.001] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id f-dMXHfJAOvj for ; Wed, 19 Apr 2006 14:23:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from fep05.ttnet.net.tr (mail.ttnet.net.tr [212.175.13.129]) by postgresql.org (Postfix) with ESMTP id 0A6D511F8C75 for ; Wed, 19 Apr 2006 14:23:55 -0300 (ADT) Received: from (192.168.8.105) by AVGW-I-1.ttnet.net.tr via smtp id 2038_08cf3bd8_cf9f_11da_8725_001422175f0e; Wed, 19 Apr 2006 15:21:32 +0300 Received: from alamut ([85.101.242.156]) by fep05.ttnet.net.tr with ESMTP id <20060419172354.OEDR1268.fep05.ttnet.net.tr@alamut>; Wed, 19 Apr 2006 20:23:54 +0300 Date: Wed, 19 Apr 2006 20:21:18 +0300 From: Volkan YAZICI To: Wiebe Cazemier Cc: pgsql-sql@postgresql.org Subject: Re: Primary key reference count Message-ID: <20060419172117.GA206@alamut> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.1i X-NAI-Spam-Rules: 1 Rules triggered BAYES_00=-2.5 X-Archive-Number: 200604/129 X-Sequence-Number: 24938 On Apr 19 02:01, Wiebe Cazemier wrote: > I'm trying to find which of the tables in pg_catalog contains the amount of > references to a primary key, but I can't seem to find it. Here's simple query, to list which table's which columns references to a specific table. (Hope this is what you asked for.) SELECT TBL.table_name, COL.column_name FROM information_schema.referential_constraints AS REF INNER JOIN information_schema.table_constraints AS TBL USING (constraint_name) INNER JOIN information_schema.constraint_column_usage AS COL USING (constraint_name) INNER JOIN information_schema.table_constraints AS PRI ON (PRI.constraint_name = REF.unique_constraint_name) WHERE PRI.table_name = 'pri_id'; -- Your target table goes here. This is a quick & dirty hack. Just wanted to show the possibility of the idea using information schema. (You don't want to deal with internal tables, ain't?) Regards.