Re: unique across two tables

Поиск
Список
Период
Сортировка
От tv@fuzzy.cz
Тема Re: unique across two tables
Дата
Msg-id 9928b10d5090b793d6ae56dcd62f0fc7.squirrel@sq.gransy.com
обсуждение исходный текст
Ответ на unique across two tables  (Tarlika Elisabeth Schmitz <postgresql4@numerixtechnology.de>)
Список 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?

You can't have a constraint spreading multiple tables. And fixing this
using a trigger is harder than it looks, because a trigger does not see
uncommited changes made by other sessions.

So for example this will be hard to catch:

Session A: INSERT INTO town(name) VALUES ('Chicago');
Session B: INSERT INTO town(name) VALUES ('Chicago');
Session A: COMMIT;
Session B: COMMIT;

What I'd do is I'd keep the primary name in the 'townalias' table too,
maybe with a 'primary=true' flag. That way you can use traditional UNIQUE
constraint.

regards
Tomas


В списке pgsql-general по дате отправления:

Предыдущее
От: Tarlika Elisabeth Schmitz
Дата:
Сообщение: unique across two tables
Следующее
От: salah jubeh
Дата:
Сообщение: Re: connection time out