more than just (m:n)?

Поиск
Список
Период
Сортировка
От Arda Çeşmecioğlu
Тема more than just (m:n)?
Дата
Msg-id 4F567A17.4030102@gmail.com
обсуждение исходный текст
Список pgsql-novice
Hello,

I need a relationship between say table A and table B having primary
keys pkA and pkB respectively.
It seems like a (m:n) (if I did get the idea of this kind of
relationship right). So a table AtoB may be like;

CREATE TABLE "AtoB"(
     "fk_pkA" integer NOT NULL REFERENCES "tblA" ("pkA"),
     "fk_pkB" integer NOT NULL REFERENCES "tblB" ("pkB"),
     PRIMARY KEY ("fk_pkA","fk_pkB")
);

What I want to accomplish is to have either 0, 1 or 3 (not 2 or more
than 3) of a particular fk_pkB value.
Now if I add another column and a CHECK;

CREATE TABLE "AtoB"(
     "fk_pkA" integer NOT NULL REFERENCES "tblA" ("pkA"),
     "fk_pkB" integer NOT NULL REFERENCES "tblB" ("pkB"),
     "chkcol" text CHECK("chkcol" IN('a','b','c')),
     PRIMARY KEY ("fk_pkA","fk_pkB")
     UNIQUE("fk_pkB","chkcol")
);

This makes sure that no more than 3 rows with the same pkB value but
still allows for 2 rows.
Any ideas?

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

Предыдущее
От: "Daniel Staal"
Дата:
Сообщение: Re: Database not browsable during COPY on PostgreSQL
Следующее
От: Merlin Moncure
Дата:
Сообщение: Re: Slow duplicate deletes