Re: [GENERAL] CHECK for 2 FKs to be non equal

2017-03-11 Thread Alexander Farber
Thank you Alban and Francisco -

On Sat, Mar 11, 2017 at 11:52 AM, Alban Hertroys  wrote:
>
> > On 11 Mar 2017, at 10:41, Alexander Farber 
> wrote:
> >  uid integer NOT NULL REFERENCES words_users(uid) CHECK (uid <>
> author) ON DELETE CASCADE,
>
>
> You put your CHECK constraint definition smack in the middle of the FK
> constraint definition, which starts with REFERENCES and ends with the
> delete CASCADE.
>
>
you are both correct!


Re: [GENERAL] CHECK for 2 FKs to be non equal

2017-03-11 Thread Alban Hertroys

> On 11 Mar 2017, at 10:41, Alexander Farber  wrote:
> 
>  uid integer NOT NULL REFERENCES words_users(uid) CHECK (uid <> 
> author) ON DELETE CASCADE,

> but get syntax error in 9.5:
> 
> ERROR:  syntax error at or near "ON"
> LINE 2: ...REFERENCES words_users(uid) CHECK (uid <> author) ON DELETE …

You put your CHECK constraint definition smack in the middle of the FK 
constraint definition, which starts with REFERENCES and ends with the delete 
CASCADE.

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.



-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] CHECK for 2 FKs to be non equal

2017-03-11 Thread Francisco Olarte
Alexander:

On Sat, Mar 11, 2017 at 10:41 AM, Alexander Farber
 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.


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general