pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
constraint with check
2+ messages / 2 participants
[nested] [flat]

* constraint with check
@ 2010-12-13 23:36 Viktor Bojović <viktor.bojovic@gmail.com>
  2010-12-14 07:12 ` Re: constraint with check Jasen Betts <jasen@xnet.co.nz>
  0 siblings, 1 reply; 2+ messages in thread

From: Viktor Bojović @ 2010-12-13 23:36 UTC (permalink / raw)
  To: pgsql-sql

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=true
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=true)

thanx in advance

-- 
---------------------------------------
Viktor Bojović
---------------------------------------
Wherever I go, Murphy goes with me

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: constraint with check
  2010-12-13 23:36 constraint with check Viktor Bojović <viktor.bojovic@gmail.com>
@ 2010-12-14 07:12 ` Jasen Betts <jasen@xnet.co.nz>
  0 siblings, 0 replies; 2+ messages in thread

From: Jasen Betts @ 2010-12-14 07:12 UTC (permalink / raw)
  To: pgsql-sql

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);





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2010-12-14 07:12 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-12-13 23:36 constraint with check Viktor Bojović <viktor.bojovic@gmail.com>
2010-12-14 07:12 ` Jasen Betts <jasen@xnet.co.nz>

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