Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fazMz-0007gq-0b for pgsql-general@arkaria.postgresql.org; Thu, 05 Jul 2018 08:12:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fazMw-0005FW-P1 for pgsql-general@arkaria.postgresql.org; Thu, 05 Jul 2018 08:12:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fazMw-0005FP-Eg for pgsql-general@lists.postgresql.org; Thu, 05 Jul 2018 08:12:02 +0000 Received: from mail-it0-x22b.google.com ([2607:f8b0:4001:c0b::22b]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fazMp-0003E4-P3 for pgsql-general@lists.postgresql.org; Thu, 05 Jul 2018 08:12:01 +0000 Received: by mail-it0-x22b.google.com with SMTP id 188-v6so11104928ita.5 for ; Thu, 05 Jul 2018 01:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=8gfx40Ff2b3pTAlbcEOa0VhwIPCPCSzhi+fQQsth/N8=; b=BaEDs0j9ZVIZwJEo7ybSyxFnD2oBsN1BuIpctBSa/kkN/xaWAkDAWusHoKFzdj6s8i kcxaK4zFo+r2DZ7B1clTnhiSLmgRAANOsQ9wv87KAq+1LWxDn66sDdMNPMMmBjevPooR WRQ/vljC8fv/5zGLV5R9fwF27XDWbRrmX8yZMXEdfLTSWjW2PQCnFVhxPxaiz2T2qhfL UNa+d0bcUJFarULkUdRYuHipFDxyXDohDj2omggzvstXwAZnwnfmkRhnk/f29l3DgCT8 o0KBI5YBAOTjLovC7JCUJeUrL1sxPd5iZRqqV0oIHIodeHsTK05EFP/qzit09Xmwp0Eh c0Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=8gfx40Ff2b3pTAlbcEOa0VhwIPCPCSzhi+fQQsth/N8=; b=BlT5Gkj4c2Z4YAXzM6yweod8pzXACuALrNsM5UBbh/Ju8A3QezGAW1y5obzyeenCYV B5mZNetkdnTqt5uKnzvt6+ya4v1H8bEvBr/t5dpagPxmHU9jvWC+LVYCRYt2wgtPFDk2 xlgR9lO9QC1+r0vpd7gcBaqELAN2FbrMviUiIzFlur2VR9VbWCjdDEkDXAGaGYr24A7A /orgEYYwfhSNs5klZPISB+apJEoGSavP3oVULgCfdU6E72pTM9+M6qIJ+iMDRSz7sHUv 8NUcu/VYn64PoHUNs9V9FZ0mibcIIeTpWeedOmp5IFzbiX1zzjYmdoec+vktpWUNRqBE 3c+w== X-Gm-Message-State: APt69E3Xizl9Jq5IV6ini5Sb9V4mO3IRPLyVUN1xHbF3hNBr4DE6U+EJ 8us9ipLoKWUM2GJ8CdcqPuA= X-Google-Smtp-Source: AAOMgpdkhDxTzBF9ejWf/upH8Mzl/4b/mOAI4/qcJG9C+mzNAhAaOp+l8uw/kGtjVPfHSgu1LP8fXg== X-Received: by 2002:a02:9891:: with SMTP id q17-v6mr4034026jaj.78.1530778313559; Thu, 05 Jul 2018 01:11:53 -0700 (PDT) Received: from [192.168.1.140] (c-98-202-193-197.hsd1.ut.comcast.net. [98.202.193.197]) by smtp.gmail.com with ESMTPSA id q3-v6sm2750642itc.22.2018.07.05.01.11.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jul 2018 01:11:53 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.4 \(3445.8.2\)) Subject: Re: FK v.s unique indexes From: Rob Sargent In-Reply-To: <69628a66-c6a6-339a-f2e3-1d2df4612350@ztk-rp.eu> Date: Thu, 5 Jul 2018 02:11:51 -0600 Cc: "pgsql-general@lists.postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <3F47B63F-E3CE-4FF7-9632-D0B9C7FF75C3@gmail.com> References: <69628a66-c6a6-339a-f2e3-1d2df4612350@ztk-rp.eu> To: Rafal Pietrak X-Mailer: Apple Mail (2.3445.8.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Jul 5, 2018, at 1:30 AM, Rafal Pietrak wrote: >=20 >=20 >=20 > W dniu 04.07.2018 o 00:55, David G. Johnston pisze: >> On Tuesday, July 3, 2018, Rafal Pietrak > > wrote: >>=20 >>=20 >> ERROR: there is no unique constraint matching given keys for = referenced >> table "test2" >> ---------------------------- >>=20 >> I cannot see any reasons why this functionality is blocked. >>=20 >> In particular, contrary to what the ERROR says, the target table = *does >> have* a "unique constraint matching given keys", admittedly only >> partial. >>=20 >>=20 >> You are making the common error of confusing the distinct concepts of >> constraints and indexs. Table constraints cannot be partial by >> definition, and are a logical concept constraining the data model.=20 >=20 > Hmmm.. >=20 > This does not match "my reality". Naturally I may be wrong, but the > example I've posted reflects my actual data I'm putting into the = RDBMS. > That is: > 1. the data has unique constraint on (load,a,b,c) > 2. and the data have additional unique constraints on (load,a), = provided > c is true, and (load,b) whenever c is false. >=20 > Pls consider in real life: load (a person), can have either a (a kind = of > brest cancer); or b (a kind of prostrate) - this is only a cooked > example attemping to illustrate, that one may need to put additional > constraints on the entire dataset. >=20 =20 It=E2=80=99s difficult enough to define a unique person (without mother = and father) and certainly this weeks definition of burden is not likely = to help matters. If you=E2=80=99re main worry is data consistency you = might be better off normalizing your structure - either with separate = tables per cancer type (person id, cancer specifics; unique on person) = or in a single table one per line (person id, cancer type, cancer = description; unique on person). You can reconstitue = person,breast,prostate from either of those. We won=E2=80=99t quibble = on one person having both (though remotely possible, men do get breast = cancer).