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

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: number of referencing and referenced columns for foreign key disagree
Date: 2017-07-29 15:00:11
Message-ID: CAADeyWhmvZcn6AnpU4nc-d9PyVYsq7jd55jv2fz9f-xC0FGrcg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)sss(dot)pgh(dot)pa(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message marcelo 2017-07-29 19:16:13 Schemas and serials
Previous Message Tom Lane 2017-07-29 13:41:41 Re: number of referencing and referenced columns for foreign key disagree