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 1hLtk5-0006ZG-Ux for pgsql-general@arkaria.postgresql.org; Wed, 01 May 2019 18:14:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hLtk4-0001oP-Em for pgsql-general@arkaria.postgresql.org; Wed, 01 May 2019 18:14:04 +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 1hLtk3-0001lk-9G for pgsql-general@lists.postgresql.org; Wed, 01 May 2019 18:14:04 +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 1hLtk0-0004Oy-GH for pgsql-general@postgresql.org; Wed, 01 May 2019 18:14:01 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id CDC3D21BA9; Wed, 1 May 2019 14:13:59 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 01 May 2019 14:13:59 -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=6 ComvN5r361002Ffk1ODlEbGkVzoK88JgsBAHSH/YHM=; b=ShDC52i0vbLTJP6Vu b3RuHvsnac/ZONqa1KBgYWAer9rfMcmllnKV9L3jDCiBkOf2857eH/D31VBd1zM1 24SjAK8nXXHLJLOROSir+s0r+V8xio6Nb26xz/8bSC6qwgiVen4xztDrP9QXTkie Y8Z0EyROJ+7WwL6/ACUC+lghAGK3ZatZVJ2kraWjclih6brcY/IMyAExu5fEJy0c iS/7vLhkN54btGsjinbMWwCz76lOMjlzGdiHN5hlT1vWc7yasFTp3lxNZjt/w6RA DpehF76QVgQzD482k8vm74xQJiwfuX4zw6XMZFXcNZJykYLRHK+2mzIcaVcULeNN ZtN5Q== 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=6ComvN5r361002Ffk1ODlEbGkVzoK88JgsBAHSH/Y HM=; b=v86jbI0vI52BvsdJgFYnPaE7W5n6KnXAXNq2FNpbuSLuZEWxqM+iWnsRh b03jVaY4vAFQ/7BOiFBqNHg8x8E6xhxdTnOEEvWHCA8+mZGCkNUmZbX5ymRJGa/n sOR/u3yjeQKHZ94KVdTmounGcjnYA3RvclLcddw9Oa+8lmgALrkne3X397tzuaQH 3ZNLQRzvtc+9Ct4tbRBujrEBQb7gBpicnAdq+YijNpcHLNXdDrOFkXliAcLtzW7f i+U/AtK3mpc8GnZC9yKqvt9g8YaOkz6yWIeeQSMJCtQpmMLisfdl+tamQnmHdxQk Ebdk7X0ZzG6nUZrZZx7d5tArLi+cQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrieejgdduvdefucetufdoteggodetrfdotf 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 A131EE442F; Wed, 1 May 2019 14:13:58 -0400 (EDT) Subject: Re: Query not producing expected result To: Francisco Olarte Cc: Chuck Martin , pgsql-general References: <25696.1556728884@sss.pgh.pa.us> From: Adrian Klaver Message-ID: <1e416a02-099f-004b-aaeb-0521cd03e6bf@aklaver.com> Date: Wed, 1 May 2019 11:13:57 -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 11:04 AM, Francisco Olarte wrote: > Adrian: > > On Wed, May 1, 2019 at 7:57 PM Adrian Klaver wrote: >> 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 > > Because you are using two selected examples. The one with 9:52 is ok. > > The last one is misleading because you are using a constant for a > particular timestamp in MAY THE SECOND wich can be written to look > like it is in MAY THE FIRST. > > Rewrite it as > select '2019-05-02'::timestamp <= '2019-05-01 24:00'::timestamp; > > And you'll see and out of range date selected. Technically it is correct as: test_(postgres)# select '2019-05-02'::timestamp; timestamp --------------------- 2019-05-02 00:00:00 which is Midnight and is both the end of one day and start of another. It comes down to where you want to draw the line between days. > > This is why <= AND 24:00 are bad and misleading. > > You may not have problems with 00:00:00 times, but work a bit billing > phone calls and you'll find about one in 86400 hit it ( more in my > case as traffic distribution is skewed ). Use that kind of condition > and you end up chasing why the monthly report has a dozen less calls > than the sum of the daily ones the billing guys made using excel. > > Francisco Olarte. > -- Adrian Klaver adrian.klaver@aklaver.com