dbTalk Databases Forums  

[SQL] constraint with check

mailing.database.pgsql-sql mailing.database.pgsql-sql


Discuss [SQL] constraint with check in the mailing.database.pgsql-sql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Viktor Bojović
 
Posts: n/a

Default [SQL] constraint with check - 12-13-2010 , 05:36 PM






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

Reply With Quote
  #2  
Old   
Jasen Betts
 
Posts: n/a

Default Re: [SQL] constraint with check - 12-14-2010 , 01:12 AM






On 2010-12-13, Viktor Bojović <viktor.bojovic (AT) gmail (DOT) com> wrote:
Quote:
--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);



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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.