Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 32D559FA456 for ; Mon, 25 Dec 2006 18:25:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 01016-01 for ; Mon, 25 Dec 2006 18:25:30 -0400 (AST) X-Greylist: delayed 00:33:09.366687 by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 4714E9F9312 for ; Mon, 25 Dec 2006 18:25:30 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from cicero2.cybercity.dk (cicero2.cybercity.dk [212.242.40.53]) by svr4.postgresql.org (Postfix) with ESMTP id 0F44A5AF8AA for ; Mon, 25 Dec 2006 21:52:19 +0000 (GMT) Received: from agile.dk (0x3e42da3b.adsl.cybercity.dk [62.66.218.59]) by cicero2.cybercity.dk (Postfix) with ESMTP id 5251E24814F for ; Mon, 25 Dec 2006 22:52:03 +0100 (CET) Received: from mail.agile.dk (localhost [127.0.0.1]) by agile.dk (Postfix) with ESMTP id 421EFBBA for ; Mon, 25 Dec 2006 22:52:03 +0100 (CET) Received: from 62.66.218.59 (SquirrelMail authenticated user jma@agile.dk) by mail.agile.dk with HTTP; Mon, 25 Dec 2006 22:52:03 +0100 (CET) Message-ID: <1404.62.66.218.59.1167083523.squirrel@mail.agile.dk> Date: Mon, 25 Dec 2006 22:52:03 +0100 (CET) Subject: Related tables to a view From: "Jan Meyland Andersen" To: pgsql-sql@postgresql.org User-Agent: SquirrelMail/1.4.4 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.135 tagged_above=0 required=5 tests=BAYES_60, FORGED_RCVD_HELO X-Spam-Level: * X-Archive-Number: 200612/169 X-Sequence-Number: 27125 Hi I need a function which are able to return the underlying tables to a view. If I have a view which is a selection from field1 and field2 from table1 and field1 and field2 from table2. How can I make a selection which returns the relation for the fields in a way so I am able to se which field belongs to which table. SELECT * FROM pg_views WHERE viewname='TestView' will return the schema and the definition for me. SELECT * FROM pg_class WHERE relname = 'TestView' will return some oids etc. SELECT * FROM pg_attribute JOIN pg_class ON attrelid = pg_class.oid AND pg_class.relname='TestView' will return the fields including oids etc. But I just cant find out how to find the tables for each field. I hope someone are able to help me with this problem. Regards Jan Andersen