Problem with n to n relation

From: Janning Vygen <vygen(at)planwerk6(dot)de>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Problem with n to n relation
Date: 2001-10-05 10:39:40
Message-ID: 0110051239400B.30993@janning
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

i create n to n relations like this, right?

create table person (
id serial,
name text
);

create table address (
id serial,
street text
...
);

create table person2adress (
id serial,
person_id integer not null references person(id),
address_id integer not null references address(id),
);

than i can select all adresses from one person with id =1 with
select street
from address
where id =
(
select adress_id
from person2adress
where person_id = 1
);

ok so far so good. but you can still insert persons without any
adress. so its a 0..n relation. But how van i achieve that you can´t
insert any person without adress???

thanks in advance
janning

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Vladimir Vukicevic 2001-10-05 11:06:45 getting OID from PL/PgSQL AFTER trigger
Previous Message Markus Bertheau 2001-10-05 06:48:57 Re: strange query execution times