Re: Database Views

From: Frank Bax <fbax(at)sympatico(dot)ca>
To:
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Database Views
Date: 2008-11-06 17:45:38
Message-ID: 49132D42.30803@sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

gcj wrote:
> I have the following three tables: CARS TRUCKS SUVS
>
> Although the tables contain numerous columns each, they each contain the
> following columns in common:
>
> Manufacturer
> Identification Number
> Color
>
> I would like to create a view that will display this common information
> as well as a column called “Type” that will indicate what kind of record
> it is – eg Car, Truck, or SUV.

create table car (manufacturer varchar, vin varchar, color varchar);
create table truck (manufacturer varchar, vin varchar, color varchar);
create table suv (manufacturer varchar, vin varchar, color varchar);

insert into car values('Toyota','TTT', 'Silver');
insert into truck values('Mack','QQQ', 'Black');
insert into suv values('Lexxus','ZZZ', 'Yellow');

create or replace view vehicle as
select 'car' as type,manufacturer,vin,color from car
union
select 'truck' as type,manufacturer,vin,color from truck
union
select 'suv' as type,manufacturer,vin,color from suv
;

select * from vehicle;

type | manufacturer | vin | color
-------+--------------+-----+--------
car | Toyota | TTT | Silver
suv | Lexxus | ZZZ | Yellow
truck | Mack | QQQ | Black

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2008-11-06 17:50:22 Re: Database Views
Previous Message gcj 2008-11-06 17:21:11 Database Views