pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jasen Betts <jasen@xnet.co.nz>
To: pgsql-sql@postgresql.org
Subject: Re: constraint with check
Date: 14 Dec 2010 07:12:31 GMT
Message-ID: <ie75cv$9jg$1@reversiblemaps.ath.cx> (raw)
References: <AANLkTimx6AsyFJnocPk2-nx1MqUvGbSY3W8JWQmE2dRn@mail.gmail.com>

On 2010-12-13, Viktor Bojović <viktor.bojovic@gmail.com> wrote:
> --0015175cd20209e2030497532e39
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: quoted-printable
>
> Hi
> im trying to create foreign key constraint which checks not only the
> existence of key in foreign table, but it has to check if node field has
> value=3Dtrue
> but i don't know how to do that, so im asking for help.

> alter table wg.nc
> add CONSTRAINT "nc_fk" FOREIGN KEY ("Id1")
>   REFERENCES "wg"."entities"("Id"),
> check (node=3Dtrue)

you can't do that.

add a node column to wg (and a check node is not distinct fron true constaint and default true) then do this

 alter table wg.nc
 add CONSTRAINT "nc_fk" FOREIGN KEY ("Id1",node)
   REFERENCES "wg"."entities"("Id",node);





view thread (2+ messages)

Message-ID: <ie75cv$9jg$1@reversiblemaps.ath.cx>
Permalink:  ../ie75cv$9jg$1@reversiblemaps.ath.cx/
Also on:    postgresql.org/message-id/ie75cv$9jg$1@reversiblemaps.ath.cx

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jasen@xnet.co.nz
  Subject: Re: constraint with check
  In-Reply-To: <ie75cv$9jg$1@reversiblemaps.ath.cx>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox