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 1gkBMa-00060J-Dk for pgsql-general@arkaria.postgresql.org; Thu, 17 Jan 2019 17:21:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gkBMZ-0000YO-46 for pgsql-general@arkaria.postgresql.org; Thu, 17 Jan 2019 17:21:55 +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 1gkBMY-0000YH-OG for pgsql-general@lists.postgresql.org; Thu, 17 Jan 2019 17:21:54 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gkBMV-0003pt-QV for pgsql-general@lists.postgresql.org; Thu, 17 Jan 2019 17:21:53 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id C983323D15; Thu, 17 Jan 2019 12:21:50 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 17 Jan 2019 12:21:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=y lChJcITGe7S9YQ20/o5aiJdT/aatet/oZORQH03EdQ=; b=dDsFPwU40P1DSmLyG gQPHOVCfMuiEQazCTfujAeHBU5G9TstFItHmchYfO4KeU1jmFXPTyj+0jvZ+CgBM uXjeBOcd/R3QQRrAfqaIRYSP1W20a5+15RP/RbrhXFi4PYc3L8Ra+A0kuZ3Rvq1r YZdQ6vmAZ384XLLFUxarUKlt3p6X8xfha2HRS7vHb7uHHDQ7DF0Cx70AE0bG3xAW qiUPTTiUDNQ98IT0XRXPAYTZwc8HXD6Nk/GtXS7m6S0Ys7OFt80fWiRUJIK6kVpf klyo5ws6AzMvij+ePGLEe9Y1aO5jzUm+Nyh3a2jVaAzseNDkZw4iWg12P9rZXd5q RK8Tg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm1; bh=ylChJcITGe7S9YQ20/o5aiJdT/aatet/oZORQH03E dQ=; b=sl4lg3Ylw7qnPjB2fpYrel1lcc+LJEfY7YsVAkY/XNmto975Qic4UGVEA mulC0B8oiC/Nl7KAUMDKbvvl8gSgn3Jn4bWVfpNJP4nADzCGhyy0YMXuyZuEMUwT K9aRh3VfWkv9pLOkwlsq+JPo/EaKPtuVb0nwnMTvoCdBDm3PB+/RWIGMb5EdvTTV JXj2te5Q+gJJ0ctM3r48sfIh3TLkZkbBaVhUw6BsBTd1b6FUspyu++E43GusuGYm pBwtM6mQkK8Mkc3FNIIDsM9LkC6OY7ke7tdjcJVQPHuSm7c0Z1bSb5kwK1xs0bg4 sjZ6+80MBSz7VyrXvxaoEoqjz+1rQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrgeekgdelgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepuffvfhfhkffffg ggjggtgfesthekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegr ughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucffohhmrghinhepph hoshhtghhrvghsqhhlrdhorhhgnecukfhppeejfedrvdefledruddujedrvdefkeenucfr rghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrh drtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from ranger.suse (c-73-239-117-238.hsd1.wa.comcast.net [73.239.117.238]) by mail.messagingengine.com (Postfix) with ESMTPA id E5714100BB; Thu, 17 Jan 2019 12:21:49 -0500 (EST) Subject: Re: Refining query statement To: Rich Shepard , pgsql-general@lists.postgresql.org References: <9a5976c8-76da-f06d-9840-5dcf8723e38b@gmx.net> From: Adrian Klaver Message-ID: <7cbcfe0e-813e-b25e-f90e-dbf1e04f5076@aklaver.com> Date: Thu, 17 Jan 2019 09:21:48 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/17/19 9:07 AM, Rich Shepard wrote: > On Thu, 17 Jan 2019, David G. Johnston wrote: > >> Yes...though now it just sounds like a flawed data model. > > David, > >   This is what I thought. > >> How stuck are you in that regard? Those "future" contacts should have >> their >> own records and not be derived via an optional field on an existing >> record. > >   My goal is to make a functioning business tracking application for my > consulting services. Almost all my prior postgres databases hold > environmental data for statistical and spatio-temporal analyses so > writing a > business application is a new experience for me and I want to get it > correct. > >> Put differently, how do you know which activities are completed and >> which are not? > >   The direct answer is that a completed activity has a row with either a > future next-activity date or a null (which is the case when the status of > that organization or contact is 'no further contact'.) To be clear the next-activity date = next_contact in the database, correct? NULL basically means unknown, so having it stand for something is a bit of a stretch. Seems to me a boolean field of name active to denote contacts you need to keep up with is in order. Then make the next_contact field NOT NULL and replace the current NULL values with 'infinity': https://www.postgresql.org/docs/10/datatype-datetime.html 8.5.1.4. Special Values As to current situation: 1) Use my previous suggestion. or 2) WHERE COALESCE(next_contact, 'infinity') BETWEEN '01/01/2019'::date AND 'today'::date https://www.postgresql.org/docs/10/functions-conditional.html#FUNCTIONS-COALESCE-NVL-IFNULL > >   I should rename the Contacts table as People and the Activities table as > Contacts. The original names came from a sales management system I used > as a > design guide, but they're probably confusing to others as well as to me. > :-) > >   I can provide my current schema (eight tables) to the list (perhaps > as an > attachment), an individual, or put in on a cloud site and pass the URL. > > Thanks, > > Rich > -- Adrian Klaver adrian.klaver@aklaver.com