Search Postgresql Archives

Re: number of referencing and referenced columns for foreign key disagree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx> 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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux