Re: [GENERAL] number of referencing and referenced columns forforeign key disagree

Поиск
Список
Период
Сортировка
От Alexander Farber
Тема Re: [GENERAL] number of referencing and referenced columns forforeign key disagree
Дата
Msg-id CAADeyWhmvZcn6AnpU4nc-d9PyVYsq7jd55jv2fz9f-xC0FGrcg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [GENERAL] number of referencing and referenced columns for foreign key disagree  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Thank you, Tom! 

Should I have the CHECK in the new table written out again as in -

On Sat, Jul 29, 2017 at 3:41 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
You have to use the separate-constraint FK syntax:

CREATE TABLE words_payments (
        sid     text        NOT NULL,
        social  integer     NOT NULL ... ,
        foreign key (sid, social) references words_social
);

Or in even more pedantic detail:

        foreign key (sid, social) references words_social (sid, social)

You'd have to use that if (sid, social) were not the PK of words_social
but just some random unique key.


 CREATE TABLE words_payments (
        sid     text        NOT NULL,
        social  integer NOT NULL CHECK (0 < social AND social <= 64), /* should I add this? */
        trans   text      NOT NULL,
        paid    timestamptz NOT NULL,
        price   integer  NOT NULL CHECK (price > 0),
        FOREIGN KEY (sid, social) REFERENCES words_social (sid, social) ON DELETE CASCADE
);

Regards
Alex

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [GENERAL] number of referencing and referenced columns for foreign key disagree
Следующее
От: marcelo
Дата:
Сообщение: [GENERAL] Schemas and serials