Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hxCpp-0007zw-5p for pgsql-general@arkaria.postgresql.org; Mon, 12 Aug 2019 16:06:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hxCpn-0000fN-RB for pgsql-general@arkaria.postgresql.org; Mon, 12 Aug 2019 16:06:11 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hxCpn-0000fF-Hq for pgsql-general@lists.postgresql.org; Mon, 12 Aug 2019 16:06:11 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hxCpg-0002vi-Fo for pgsql-general@postgresql.org; Mon, 12 Aug 2019 16:06:11 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 893BA34E; Mon, 12 Aug 2019 12:06:01 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 12 Aug 2019 12:06:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=K W2JWdY4MHgXPa7Di4coKzTugxar6ojpgFihRCGMnGE=; b=SwgV/yKnvRvL0XF3y NEX68d103KytdfCTa8Wjc90lwfSvYMfVWQdhAvpRCoxHg8igYCGHrY1KSuwtiCCm foZv7PZSTAvL1xo7lnmPaErr19M0SPH8wf+sgdsgQ/29jyqYodHiWeRLFJMEf3s/ zzlKLwyKqO3xqRaVze6N4KLs75DOY4fRfJL4wVltHEDM7GbG3trEvVN3O507ssOw +of2eNjRlZnZZQdE1nijFE0jmBpw2ORRYHYO+vCCAJTiv3WxDmjDcndLS4KZ6oxx DCAuDBvv3ebiRk7LTxGHBr1xPLrRG0Hkqc8Cl+Q0Bbx0uHEGw5XqK/jwHyjRQ5OD YNrpw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=KW2JWdY4MHgXPa7Di4coKzTugxar6ojpgFihRCGMn GE=; b=aKR0NQL82/ZL09fSczFJkW6Qwf1OofP92QxBDebFNiY6ol7f57/HIuArB ddOXFZ6VhvcBze3CqmuGWLYbb+tOY9YneW6dBv7+92LvSsj5RTSgEHdTi2ASMOFo XGLgAbECWA9mRQmRdLDFNxCiAn4rX0ilK+HOuXzZ0xlwkNqUF9NAM4jOfFQ/Vw7c 8VSBzQOkGtOhHdiqVpMPXlfrUi86/vOWoRCqDgpPe3r1RqRGJDEpSelgvuHnjc8z DQ4POpBzG7r/WBT5hhinufBCjgwxY3cCt/cXnyJmaRsMeVW5/Anhf0kK9IvSYaUl VmMyZ9XmhhZHUGOaZVvqaUgeHRs5g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddruddvgedgleekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvsh hqlhdrohhrghenucfkphepjeegrdelfedruddthedrudekieenucfrrghrrghmpehmrghi lhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhenucevlh hushhtvghrufhiiigvpedt X-ME-Proxy: Received: from ranger.suse (74-93-105-186-washington.hfc.comcastbusiness.net [74.93.105.186]) by mail.messagingengine.com (Postfix) with ESMTPA id A66A7380076; Mon, 12 Aug 2019 12:05:58 -0400 (EDT) Subject: Re: constrain with MATCH full and NULL values in referenced table To: stan References: <20190812151115.GA8819@panix.com> <71e23df2-57ea-9d53-da33-5a5a0d4d695d@aklaver.com> <20190812155151.GA13116@panix.com> Cc: pgsql-general From: Adrian Klaver Message-ID: <708fdc69-c14d-8829-fb9c-ee4862712eaf@aklaver.com> Date: Mon, 12 Aug 2019 09:05:57 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190812155151.GA13116@panix.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 8/12/19 8:51 AM, stan wrote: Please reply to list also. Ccing list. > On Mon, Aug 12, 2019 at 08:17:33AM -0700, Adrian Klaver wrote: >> On 8/12/19 8:11 AM, stan wrote: >>> I am creating a table that has 2 values in it which are keys pointing to 2 >>> other tables. I need for the UNIQUE combination of these 2 keys to exist in >>> a fourth table. It has been recommended to use a foreign key constraint with >>> the MATCH FULL parameter. >> >> Without the table schema it difficult for me to figure out what it is you >> are attempting. >> >> See below for how MATCH FULL works: >> >> https://www.postgresql.org/docs/11/sql-createtable.html >> > From that page: > > MATCH FULL will not allow one column of a multicolumn foreign key to be null > unless all foreign key columns are null; if they are all null, the row is > not required to have a match in the referenced table. > > I think that means that what I am trying to enforce will not work. > > The table the insert is on has 2 columns, each of these is a foreign key to > other table. I need the unique combination of these 2 keys to exist in a 3rd > table that is a rate table. It has 3 columns, key 1, key 2, and rate. Looks > like to me, if neither of the 2 keys are in the rate table the constraint > will allow the insert. Do I have this wrong? The docs are referring to a multicolumn FK so something like: create table parent_tbl(fld_1 integer, fld_2 integer, UNIQUE(fld_1, fld_2)); create table child_tbl(fk_fld_1 integer, fk_fld_2 integer, FOREIGN KEY (fk_fld_1, fk_fld_2) REFERENCES parent_tbl(fld_1, fld_2)); \d child_tbl Table "public.child_tbl" Column | Type | Collation | Nullable | Default ----------+---------+-----------+----------+--------- fk_fld_1 | integer | | | fk_fld_2 | integer | | | Foreign-key constraints: "child_tbl_fk_fld_1_fkey" FOREIGN KEY (fk_fld_1, fk_fld_2) REFERENCES parent_tbl(fld_1, fld_2) Not sure what your setup is. That is why it is important to show the actual schema. > > -- Adrian Klaver adrian.klaver@aklaver.com