| From: | Tarlika Elisabeth Schmitz <postgresql4(at)numerixtechnology(dot)de> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | unique across two tables |
| Date: | 2011-06-20 15:03:07 |
| Message-ID: | 20110620160307.683ab611@dick.coachhouse |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
I have two tables, town and townalias, the latter containing alternative
town names.
I would like to ensure that a town name is unique per
country-region across the two tables.
Can I do this with a constraint ot do I need to implement the logic via
trigger?
=========
PostgreSQl 8.4
CREATE TABLE town
(
country_fk character varying(3) NOT NULL,
region_fk character varying(3) NOT NULL,
id serial NOT NULL,
"name" character varying(50) NOT NULL
)
CREATE TABLE townalias
(
country_fk character varying(3) NOT NULL,
region_fk character varying(3) NOT NULL,
town_fk integer NOT NULL,
id serial NOT NULL,
"name" character varying(50) NOT NULL,
CONSTRAINT town_townalias_fk FOREIGN KEY (country_fk, region_fk,
town_fk) REFERENCES town (country_fk, region_fk, id)
)
--
Best Regards,
Tarlika Elisabeth Schmitz
| From | Date | Subject | |
|---|---|---|---|
| Next Message | tv | 2011-06-20 15:18:47 | Re: unique across two tables |
| Previous Message | Marko Kreen | 2011-06-20 14:08:38 | Re: PostgreSQL 8.4.8 bringing my website down every evening |