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 1hxEJ5-0002mZ-9L for pgsql-general@arkaria.postgresql.org; Mon, 12 Aug 2019 17:40:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hxEJ4-0007cX-4r for pgsql-general@arkaria.postgresql.org; Mon, 12 Aug 2019 17:40:30 +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 1hxEJ3-0007cP-R3 for pgsql-general@lists.postgresql.org; Mon, 12 Aug 2019 17:40:29 +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 1hxEJ0-0003la-FU for pgsql-general@lists.postgresql.org; Mon, 12 Aug 2019 17:40:29 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id C7274459; Mon, 12 Aug 2019 13:40:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 12 Aug 2019 13:40:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=G QHi4RXhn7bxXivaCUldov4w9YU6GxdfUFHSi4QSH0k=; b=WHs1Jnpqbv27XyhR8 ZH6u593d2X+jAS+1ZPEgaac5NG37IvEvR5YyPzLhkB2POGDb8dd886EE09Wan5hq tjyoD73LlGsK/U84avINTF4JNOUknINkhYKqnXRmlft7NFkJhlpFJqIB/mMn5tcP KGvCEoZFoLAkV0gmnwKzPrSEzGJ9I64Z3zJEtsb1XtR12zmBDlaBIcOyiTzNttV3 0o5/oVpA+s1SNhSbktqRlJ/91kKZ4hgkp90pEa0LzD9maf60H44wnBvN2sdskcS6 SbDmaEbYsYUIz/+CCT9xCfGqVBCgFMtGZ6icgNgBp2gOd0iPDS4JEzLpk9vnQwes 7hFBg== 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=GQHi4RXhn7bxXivaCUldov4w9YU6GxdfUFHSi4QSH 0k=; b=bHAE96pFi/i4pEbpqSzMLxf089RwB9HOLAAaenlYx0eC/5Lpwu3SNOSJc bGEC+P5AcA7H4M8c/bFE/wdvYIwDt6WZA8BAl8sakj5yFdT33+t0w2X+xMjwtBZn nCogoZg/OTrze186DAg4fRgivBMS8YgZzaL6vQ90eP3vTJjhcdQzQpqewDQD/GHU tPfrIJhey1wCaBpKcS0D9bGYj+dXuNrdy9NIOi+K+NvCEj2AQlHTWFoaGC5xMGl/ E42l4e4ZIff92crUjfZ6ZPMMp++QeHLk3L2naqpRE06O1LawB9qJObSWnxWtB6vU hrZmnBE6iqh/2H5QaUpzRmh23VqmA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddruddvgedgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesth ejredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucfkphepjeegrdelfedruddthedrud ekieenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghk lhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt 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 8FBEB380083; Mon, 12 Aug 2019 13:40:21 -0400 (EDT) Subject: Re: Subject: Re: constrain with MATCH full and NULL values in referenced table To: stan Cc: pgsql-general@lists.postgresql.org References: <20190812170621.GA7359@panix.com> <3d326318-0b75-f499-1865-5cbbcc15dae3@aklaver.com> <20190812173006.GA7923@panix.com> From: Adrian Klaver Message-ID: <402afcca-08f0-0b10-0ffb-b6d824c6b45e@aklaver.com> Date: Mon, 12 Aug 2019 10:40:20 -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: <20190812173006.GA7923@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 10:30 AM, stan wrote: >>> The task_instance table is the one the original question was in reference >>> to. >>> >>> CREATE TABLE employee ( >>> employee_key integer DEFAULT nextval('employee_key_serial') >>> PRIMARY KEY , >>> id varchar(5) NOT NULL UNIQUE , >>> first_name varchar NOT NULL, >>> ); >>> >>> CREATE TABLE work_type ( >>> work_type_key integer DEFAULT nextval('work_type_key_serial') >>> PRIMARY KEY , >>> type smallint UNIQUE , >>> descrip varchar UNIQUE , >>> modtime timestamptz DEFAULT current_timestamp >>> ); >>> >>> CREATE TABLE rate ( >>> employee_key integer NOT NULL, >>> work_type_key integer NOT NULL, >>> rate numeric (5, 2) NOT NULL, >>> descrip varchar , >>> modtime timestamptz DEFAULT current_timestamp , >>> FOREIGN KEY (employee_key) references employee(employee_key) , >>> FOREIGN KEY (work_type_key) references work_type(work_type_key) , >>> CONSTRAINT rate_constraint UNIQUE (employee_key , work_type_key) >>> ); >>> >>> >>> CREATE TABLE task_instance ( >>> task_instance integer DEFAULT nextval('task_instance_key_serial') >>> PRIMARY KEY , >>> project_key integer NOT NULL , >>> employee_key integer NOT NULL , >>> work_type_key integer NOT NULL , >>> hours numeric (5, 2) NOT NULL , >>> work_start timestamptz , >>> work_end timestamptz , >>> modtime timestamptz DEFAULT current_timestamp , >>> descrip varchar , >> >> Aren't the marked ones below redundant?: >> >>> FOREIGN KEY (employee_key) references employee(employee_key) , >> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >>> FOREIGN KEY (project_key) references project(project_key) , >>> FOREIGN KEY (work_type_key) references work_type(work_type_key) , >> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >>> FOREIGN KEY (work_type_key , employee_key) REFERENCES rate (work_type_key , employee_key) MATCH FULL >> >> They are covered above. >> >>> ); > > OK, looks like learning time for me, again. Which is alwasy a good thing. My > thought here was that I needed to specify these on the dreivative table > (task_instnce). Are you teaching me that, since these constraints exist on > the tables that rate is derived from, I do not need to specify thmm for the > rate table? If I'm following what you are trying to do then: 1) task_instance is dependent on the information in rate being present for a given combination of (work_type_key , employee_key). 2) If 1) is correct then you cannot create a record in task_instance until a record exists in rate. 3) 2) means you have already established a relationship to employee and work_type via rate. > > The purpose of those is to verify that the key being inserted already exists > in the parent (eg employee) table. > -- Adrian Klaver adrian.klaver@aklaver.com