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 1giMYe-0003Dt-Eu for pgsql-general@arkaria.postgresql.org; Sat, 12 Jan 2019 16:54:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1giMYd-0007fg-0G for pgsql-general@arkaria.postgresql.org; Sat, 12 Jan 2019 16:54:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1giMYc-0007Zq-LF for pgsql-general@lists.postgresql.org; Sat, 12 Jan 2019 16:54:50 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1giMYa-00012P-33 for pgsql-general@lists.postgresql.org; Sat, 12 Jan 2019 16:54:49 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 2788D9934D for ; Sat, 12 Jan 2019 08:54:47 -0800 (PST) Date: Sat, 12 Jan 2019 08:54:47 -0800 (PST) From: Rich Shepard To: "pgsql-general@lists.postgresql.org" Subject: Re: insert into: NULL in date column In-Reply-To: Message-ID: References: <410b055a-24a7-5e15-f4e6-462e64794530@gmail.com> User-Agent: Alpine 2.20 (LNX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, 12 Jan 2019, David G. Johnston wrote: > NULL isn't the problem - a check constraint can resolve to unknown in > which case it behaves the same as if it resolved as true (i.e., its > basically a IS NOT FALSE test in the backend). This is actually a > nice feature of check constraints since for nullable columns you don't > have to write "col IS NULL OR " David, Thanks for correcting me. > The problem is that check constraints are only applied at time of data > change. If you insert a record whose date is 3 days from now the check > constraint passes today and (in theory) for the next couple of days. After > which the constraint fails - but you are INFORMED ONLY IF THE RECORD IS > INSERTED AGAIN. So basically you will not see a problem until you attempt > to restore your data on some future date and much of your data fails to > restore because those dates are no longer in the future. I thought that the check constraint applied at data entry, too. If not, then I'll have either wxPython or SQLAlchemy ensure that the next_contact date is later than the contact date. > If you want to check for a future date you should probably also store the > date you are comparing against and have the check constraint reference > both fields. The contact date is always entered in a new row, but the next_contact date might not be if there's nothing scheduled. Best regards, Rich