Re: Database Views - Mailing list pgsql-novice

From Frank Bax
Subject Re: Database Views
Date
Msg-id 49132D42.30803@sympatico.ca
Whole thread Raw
In response to Database Views  ("gcj" <gauss21@comcast.net>)
Responses Re: Database Views
List 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

pgsql-novice by date:

Previous
From: "gcj"
Date:
Subject: Database Views
Next
From: Tom Lane
Date:
Subject: Re: Database Views