Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 0AD3B1336971 for ; Tue, 14 Dec 2010 03:12:54 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 17631-09 for ; Tue, 14 Dec 2010 07:12:46 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtpcorp.com (smtpcorp.com [67.192.120.76]) by mail.postgresql.org (Postfix) with ESMTP id A813F13364DE for ; Tue, 14 Dec 2010 03:12:44 -0400 (AST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpcorp.com; s=main; h=Content-Transfer-Encoding:Content-Type:Mime-Version:References:Message-ID:Date:Subject:From:To; bh=dpHyxnQcnMgvjZ8Qa9Pizopts6irJVFGjrJ2tXo/R7c=; b=vcLVvjtZuqa0jggcfprFyD3X6e9WfecP8qauoD/m22N8rpK3X9JykLhP4Ha040PBuiewlff7F5SHu0X02ziuS+vbBP+szbbfuSyhaaFL79KY3bli2mS/K0OaVIZxiYix; Received: from ip-118-90-137-158.xdsl.xnet.co.nz ([118.90.137.158] helo=gonzo) by smtpcorp.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.70) id 1PSP3z-0004mg-7q; mid 144 for pgsql-sql@postgresql.org; Tue, 14 Dec 2010 07:12:43 +0000 Received: from news by gonzo with local (Exim 4.72) (envelope-from ) id 1PSP3n-0002Yk-Ns for pgsql-sql@postgresql.org; Tue, 14 Dec 2010 20:12:31 +1300 To: pgsql-sql@postgresql.org Path: not-for-mail From: Jasen Betts Newsgroups: gmane.comp.db.postgresql.sql Subject: Re: constraint with check Date: 14 Dec 2010 07:12:31 GMT Organization: Dis (not Dat) Organisation Lines: 25 Message-ID: References: NNTP-Posting-Host: localhost Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: reversiblemaps.ath.cx 1292310751 9840 127.0.0.1 (14 Dec 2010 07:12:31 GMT) X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-18 (Linux) X-Smtpcorp-Track: 18322205.1.3890699 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201012/65 X-Sequence-Number: 34901 On 2010-12-13, Viktor Bojović 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);