From: | Misa Simic <misa(dot)simic(at)gmail(dot)com> |
---|---|
To: | Tarlika Elisabeth Schmitz <postgresql4(at)numerixtechnology(dot)de> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: unique across two tables |
Date: | 2011-06-22 12:48:56 |
Message-ID: | BANLkTi=cc_M7gppf8JYu3P141Ls_+F9=Mg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi Tarlika,
I think easy solution could be:
create baseTable with just one column as PK
TableA inhertis baseTable, it will have inherited Column + additianl tables
for TableA
TableB inherits baseTable, it will aslo have inherited Column + additianl
tables for TableB
Insert in any table TableA or TableB will automatically insert row in
baseTable what will fail if value already exist...
Kind Regards,
Misa
2011/6/20 Tarlika Elisabeth Schmitz <postgresql4(at)numerixtechnology(dot)de>
> 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
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
From | Date | Subject | |
---|---|---|---|
Next Message | Simon Riggs | 2011-06-22 12:53:16 | Re: Streaming replication and temp table operations |
Previous Message | Radosław Smogura | 2011-06-22 12:48:16 | Re: Error - could not get socket error status: Invalid argument |