Re: CHECK for 2 FKs to be non equal

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: CHECK for 2 FKs to be non equal
Date: 2017-03-11 10:45:44
Message-ID: CA+bJJby+Rk-L1SD1Jy-fYkzK7_PtVqy6PUP-0C8WcSy261rN+w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alexander:

On Sat, Mar 11, 2017 at 10:41 AM, Alexander Farber
<alexander(dot)farber(at)gmail(dot)com> wrote:
> uid integer NOT NULL REFERENCES words_users(uid) CHECK (uid <>
> author) ON DELETE CASCADE,

Maybe a stupid question, but have you tried "refereces.. on delete .. check"?

I mean, the manual for create table says:

>>>

column_name data_type [ COLLATE collation ] [ column_constraint [ ... ] ]

...And a little down

where column_constraint is:

[ CONSTRAINT constraint_name ]
{ NOT NULL |
NULL |
CHECK ( expression ) [ NO INHERIT ] |
DEFAULT default_expr |
UNIQUE index_parameters |
PRIMARY KEY index_parameters |
REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL |
MATCH SIMPLE ]
[ ON DELETE action ] [ ON UPDATE action ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
<<<<

So ON DELETE is an optional part of a reference constraint, not a
constraint per se, and it is being parsed as "references..." ( correct
constraint) + "check..." (correct constraint) + "On delete.." (WTF is
this ), on delete after references should be parsed as a single big
constraint.

> What am I doing wrong please?

Not RTFM ? ( if I'm right, or not understanding it )

Francisco Olarte.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2017-03-11 10:52:27 Re: CHECK for 2 FKs to be non equal
Previous Message Alexander Farber 2017-03-11 09:41:27 CHECK for 2 FKs to be non equal