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 1hLtUB-0005fL-Ag for pgsql-general@arkaria.postgresql.org; Wed, 01 May 2019 17:57:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hLtU9-00015p-Ri for pgsql-general@arkaria.postgresql.org; Wed, 01 May 2019 17:57:37 +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 1hLtU9-0000yb-CK for pgsql-general@lists.postgresql.org; Wed, 01 May 2019 17:57:37 +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 1hLtU6-000426-Vs for pgsql-general@postgresql.org; Wed, 01 May 2019 17:57:36 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 3D7CD21FBA; Wed, 1 May 2019 13:57:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 01 May 2019 13:57:34 -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=fm2; bh=F 3t5ZUp9Z1yjnZqNlF8a+u2INuls+qxfJ+kTr+6MSYM=; b=PXVZPSwps7J+t4q6k 5/Xe5Xd3YOJc7U3RP/K8y6RsRlNIX0NXuILyEcQ8oonIM9Xap1u0gIwZy9hC2KrB 1D5SvwTdeB5u4/BOwgeC/yneO0JnG6nBg0YnoE9YbGvlpuTr79QwKCSybFU1S2UN 1LVO97cwU7N8BUCdhMVhl1OQ+HcAh56opYWqdfnVssoXdOkeFGhgjBZ4nLX8vJt5 2sgbAC9aPK4pZduCYkto0mQoGXRfyDK0zaZJRwzlvR3cxVAEMMFXqaEl5APLBouO /EXcycHjxn6GN1WDitLRjX+IXXEpfBvZfHTRPdUT4xWmhBxLxqu3eNxUpxno8Efm 3WrnQ== 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=fm2; bh=F3t5ZUp9Z1yjnZqNlF8a+u2INuls+qxfJ+kTr+6MS YM=; b=8MOCMa4STJCe/J5z6mklRKJam2WJQrx2OUHZPTPm8+iLS0PZKnHBuzVyD 4uEKigem9LXRHI/iK+lCPraQZdtODVwXgimgRu9fs7uIkYKHgvTHsN/E7+auSv0n 2XMbPW+6okT+xrdL921z74eTxqMjJLdycnezR2xc8khmcUXuHMMjn8jbZqZV9R4g BN12Ma/w5jG7B7XR9qyp99ZM86v1C4o45o7tq0BQEcFqwINzGAW3xWTrJrRriGAZ o39Jseq1pDHwsTewOhJLOl8Nbp7ihWcKxFVCvWJNvv98nsa66fDRp73lfAMWgM7F MaACUV1nLrrkE9Ubc9HpQ+LQIICDA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrieejgdduvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucfkphepjeegrdelgedrjeefrddvvddvnecurfgrrhgrmhepmhgrihhlfhhrohhm pegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrh fuihiivgeptd X-ME-Proxy: Received: from ranger.suse (unknown [74.94.73.222]) by mail.messagingengine.com (Postfix) with ESMTPA id 5066CE4382; Wed, 1 May 2019 13:57:33 -0400 (EDT) Subject: Re: Query not producing expected result To: Francisco Olarte , Chuck Martin Cc: pgsql-general References: <25696.1556728884@sss.pgh.pa.us> From: Adrian Klaver Message-ID: Date: Wed, 1 May 2019 10:57:32 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: 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 5/1/19 10:51 AM, Francisco Olarte wrote: > On Wed, May 1, 2019 at 7:37 PM Chuck Martin wrote: >> >> Something like daterange would be a solution in some circumstances, but this query is a user-generated one, and they don't have that much control over the query. It has to be modified as needed behind the scenes so that it produces the results they expect. In this instance, I'm now (given the advice received here) inclined to check the value entered when searching for a date, and if no time is entered, add '24:00' to the date. > > What I normally do for that is, if the user must enter a date, use > $user_input::date+1 and always go to less than. > > But anyway your solution with <= is incorrect. And you have made the > mistake probably because the 24:00 lead you to think postgres will > split the timestamp, compare You will have to explain further as I am not seeing it: test_(postgres)# select '2019-05-01 9:52' <= '2019-05-01 24:00'::timestamp; ?column? ---------- t test_(postgres)# select '2019-05-01 24:00' <= '2019-05-01 24:00'::timestamp; ?column? ---------- t > the date with may 1 and the time with 24:00, and that is not true. The > less-than option plus one-day add will not lead you to that error. > > You can use <= with 23:59:59.9999999999999999999, will be good for > some years if leap-seconds do not bite you. > > The problem is when the user enters a date, he wants a date search, so > cast(dateTime as date) <= limit. When he enters a time he does not > usually know what he is asking for ( normally when my users ask for > 'May 1 23:15 they want to include up to 23:15:59, users think in > "truncate to my precision, then search inclusively" ). But they begin > to understand it when I ask "ok, twice a month bills, go 1..15 and > 16..what ?", much easier to say [YYYY-MM-01 , YYYY-MM-16) and [ > YYYY-MM-16, (YYYY-MM-01)+1month) > > Francisco Olarte. > -- Adrian Klaver adrian.klaver@aklaver.com