X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 68AE1D8159 for ; Sun, 4 Sep 2005 10:00:39 -0300 (ADT) 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 77421-08 for ; Sun, 4 Sep 2005 13:00:38 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 86D71D8024 for ; Sun, 4 Sep 2005 10:00:36 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j84D0Y0T031912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 4 Sep 2005 07:00:36 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j84D0Xsj010033; Sun, 4 Sep 2005 07:00:33 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j84D0V9C010032; Sun, 4 Sep 2005 07:00:31 -0600 (MDT) (envelope-from mfuhr) Date: Sun, 4 Sep 2005 07:00:31 -0600 From: Michael Fuhr To: Neil Dugan Cc: pgsql-sql@postgresql.org Subject: Re: joining two simular (but not identical tables) Message-ID: <20050904130031.GA9978@winnie.fuhr.org> References: <1125836352.7221.7.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1125836352.7221.7.camel@localhost.localdomain> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.109 required=5 tests=[AWL=-0.098, UPPERCASE_25_50=0.207] X-Spam-Level: X-Archive-Number: 200509/26 X-Sequence-Number: 22573 On Sun, Sep 04, 2005 at 10:19:12PM +1000, Neil Dugan wrote: > I have two similar but not identical tables. > I would like to create a view that combines the contents of both tables > into a single view, where each record in each table is visible as a > separate record in the view. Sounds like you're looking for UNION. http://www.postgresql.org/docs/8.0/static/queries-union.html http://www.postgresql.org/docs/8.0/static/typeconv-union-case.html Does the following example do what you want? CREATE TABLE a (x integer, y integer); INSERT INTO a (x, y) VALUES (1, 2); INSERT INTO a (x, y) VALUES (3, 4); CREATE TABLE b (x integer, z integer); INSERT INTO b (x, z) VALUES (5, 6); INSERT INTO b (x, z) VALUES (7, 8); CREATE VIEW v AS SELECT x, y, NULL AS z FROM a UNION ALL SELECT x, NULL AS y, z FROM b; SELECT * FROM v; x | y | z ---+---+--- 1 | 2 | 3 | 4 | 5 | | 6 7 | | 8 (4 rows) -- Michael Fuhr