From viktor.bojovic@gmail.com Mon Dec 13 23:37:05 2010 Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 449C11336971 for ; Mon, 13 Dec 2010 19:37:05 -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 42485-01 for ; Mon, 13 Dec 2010 23:36:59 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f174.google.com (mail-qy0-f174.google.com [209.85.216.174]) by mail.postgresql.org (Postfix) with ESMTP id 6C75C13364DE for ; Mon, 13 Dec 2010 19:36:57 -0400 (AST) Received: by qyj19 with SMTP id 19so4084469qyj.19 for ; Mon, 13 Dec 2010 15:36:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=PjV7IfBr2U9I+qfAubh9101IcVWN4oQ8k6p7K9UTFB4=; b=sCeNPovpuzNecM+SSSo2TZk1Y1X+4bs6IAHnoEWW5EuxTwJ2Qxmx41oabjvAVlbKcq lHIlw3F4dMnyOovmiddkNO8kpxcP4FXOjHcbQtRfl+RidyMgzsX2vkVGce1FfNAJWTIS Bj8egvyX8HSPEERgnl+4KbdFJJ4OHytqjzQI0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=tStMtZDzEAy6T0Fwc8nuit0XrES0HS0bqCi9YrLCe4/XWQx93RC2okcvxBy/BUhhwe VODGBjNprg0f71MmUs1PRXae23aYdxGzlDV9RAxnuQO85TntGZ1z6CPbPO93DTNqbYXN wcYIxYgcvwm5LE65J6Ou2/W+KrFnfWnuDkJTQ= MIME-Version: 1.0 Received: by 10.224.67.85 with SMTP id q21mr4469226qai.116.1292283417321; Mon, 13 Dec 2010 15:36:57 -0800 (PST) Received: by 10.220.201.68 with HTTP; Mon, 13 Dec 2010 15:36:57 -0800 (PST) Date: Tue, 14 Dec 2010 00:36:57 +0100 Message-ID: Subject: constraint with check From: =?UTF-8?Q?Viktor_Bojovi=C4=87?= To: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary=0015175cd20209e2030497532e39 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.588 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201012/63 X-Sequence-Number: 34899 --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) thanx in advance --=20 --------------------------------------- Viktor Bojovi=C4=87 --------------------------------------- Wherever I go, Murphy goes with me --0015175cd20209e2030497532e39 Content-Type: text/html; 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 i= m asking for help.

alter table wg.nc
add CONST= RAINT "nc_fk" FOREIGN KEY ("Id1")
=C2=A0 REFERENCE= S "wg"."entities"("Id"),
check (n= ode=3Dtrue)

thanx in advance

--
----------------= -----------------------
Viktor Bojovi=C4=87
-------------------------= --------------
Wherever I go, Murphy goes with me
--0015175cd20209e2030497532e39-- From jasen@xnet.co.nz Tue Dec 14 07:12:54 2010 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);