X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A1A1811F6AC3 for ; Sun, 23 Apr 2006 12:35:26 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 46438-01-3 for ; Sun, 23 Apr 2006 12:35:16 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id E315A11F8F69 for ; Sun, 23 Apr 2006 12:28:13 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1FXgVM-0000CF-1Z for pgsql-sql@postgresql.org; Sun, 23 Apr 2006 17:28:08 +0200 Received: from 212.204.130.36 ([212.204.130.36]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 23 Apr 2006 17:28:08 +0200 Received: from halfgaar by 212.204.130.36 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 23 Apr 2006 17:28:08 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Wiebe Cazemier Subject: Re: Primary key reference count Date: Sun, 23 Apr 2006 17:27:58 +0200 Lines: 22 Message-ID: References: <20060419172117.GA206@alamut> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 212.204.130.36 User-Agent: KNode/0.9.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200604/153 X-Sequence-Number: 24962 On Wednesday 19 April 2006 19:21, Volkan YAZICI wrote: > 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?) I know the reply is somewhat late, but indeed, this would seem to be what I was looking for. And, using the information schema instead of pg_catalog would seem to be a better idea as well :)