using tables as types in other tables

From: Louis-David Mitterrand <cunctator(at)apartia(dot)ch>
To: pgsql-general(at)postgresql(dot)org
Subject: using tables as types in other tables
Date: 2001-02-14 18:35:39
Message-ID: 20010214193539.A1374@apartia.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


In the app we are developing the concept of an address will occur very
often on many tables (vendor, clients, employees, etc.) so we are
looking to avoid code duplication by centralizing the addresses in one
table. However I once read on one of the pgsql- lists that one could use
a table name as a type:

create table address(street text, zip text, city text, country text);

create table employee(emp_addr address, emp_id int);

This is accepted by Postgres but the question is how to insert into the
employee table? What syntax should be used? I tried:

insert into employee values (('mystreet','myzip','mycity','mycountry'), 1);

But it doesn't work.

Should I proceed along that path or would I be better off using a
central address table with keys to the other tables?

Thanks in advance for your insight,

--
THESEE: D'un perfide ennemi j'ai purg la nature ;
A ses monstres lui-mme a servi de pture ;
(Phdre, J-B Racine, acte 3, scne 5)

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-02-14 18:36:34 Re: Backend sent D message without prior T
Previous Message Robert Dege 2001-02-14 18:32:01 tmp_pg_shadow