X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 944A13A5890 for ; Tue, 25 Jan 2005 19:10:55 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 06713-10 for ; Tue, 25 Jan 2005 19:10:49 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id B3BA33A5862 for ; Tue, 25 Jan 2005 19:10:49 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id j0PJAj5v013890 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 25 Jan 2005 12:10:48 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id j0PJAjS1078225; Tue, 25 Jan 2005 12:10:45 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id j0PJAjdM078224; Tue, 25 Jan 2005 12:10:45 -0700 (MST) (envelope-from mfuhr) Date: Tue, 25 Jan 2005 12:10:45 -0700 From: Michael Fuhr To: Steve Castellotti Cc: pgsql-sql@postgresql.org Subject: Re: Looking up table names by REFERENCES Message-ID: <20050125191045.GA78147@winnie.fuhr.org> References: <1106579349.746.8.camel@odyssey> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1106579349.746.8.camel@odyssey> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/235 X-Sequence-Number: 20023 On Tue, Jan 25, 2005 at 04:09:09AM +1300, Steve Castellotti wrote: > Surely there's a simple way I can trace REFERENCES in a particular > column across tables? The pg_constraint table contains foreign key constraints. Here's an example query that appears to work in trivial tests: SELECT c.conname, c.conrelid::regclass, a1.attname, c.confrelid::regclass, a2.attname AS fattname FROM pg_constraint AS c JOIN pg_attribute AS a1 ON a1.attrelid = c.conrelid AND a1.attnum = ANY (c.conkey) JOIN pg_attribute AS a2 ON a2.attrelid = c.confrelid AND a2.attnum = ANY (c.confkey) WHERE c.contype = 'f'; -- Michael Fuhr http://www.fuhr.org/~mfuhr/