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 | | 67 | | 8
(4 rows)
--
Michael Fuhr