Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdwnb-0002Hf-JE for pgsql-general@arkaria.postgresql.org; Fri, 22 Oct 2021 15:49:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mdwnZ-0007Q1-FJ for pgsql-general@arkaria.postgresql.org; Fri, 22 Oct 2021 15:49:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdwnX-0007Ps-Mn for pgsql-general@lists.postgresql.org; Fri, 22 Oct 2021 15:49:36 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdwnV-00027z-0E for pgsql-general@lists.postgresql.org; Fri, 22 Oct 2021 15:49:34 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id AF96B5C019D; Fri, 22 Oct 2021 11:49:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 22 Oct 2021 11:49:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=U NTXYLETNnLVqqS5wYCQc8NcTHxUUnB+UP/RfhUzXK0=; b=O78g+QTZIItQ7wXG/ ohax1cOLiyTbgSJcnIzFCh4qLcB8/wrG+rLj7Ug/dsqx0/KCq3Ux6F1xGp7/hNZu 1zxIyP8usJGssUvkAo+eFSHqN1YWgY67YrlGDKeW6L5f5vDwGkgrdEoiefldTmSk E+W+Q8XbMDosfkBwsniZ552e5+cO2haftIm1CFahXvj4gy1KgXi0t5SNNkdGmysG tElaPZsTxTAnJFlQM6Jlhh2jKTD2HAc1Bny8rmzMHNOfr+xdivqB7cA7OaOzVzll IK36zJOWBFduDm0vId/lUoVppLw7q1jW1h68sXFjcwlIL2w2GoylSFKjOmJg29HK mOXZQ== 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=fm1; bh=UNTXYLETNnLVqqS5wYCQc8NcTHxUUnB+UP/RfhUzX K0=; b=ebdpUJ/0sHzun+25xSq1RA04RHmRWrVcxVBxZXaKAZMUjmT90j7XShpvw K2Wk42QZk4IPIkDPaIXnzmX3VnRONk4ajd3HGLrm8JYif3Kvd2K/o2yW4MevsseO rcumVHeDqDO5opkYPgpgqApbj1ehDBBw1cemZucVV3BGsZCjKsoL7I5+gZ7nFQp8 MQVDm8YZtz9R/XvFwSzEi0t1rLOazOv3m3Fold590a8TmhSrY62m4mI4t92VYorq hVTJB5TiBzaWW7hfNFnCED4JddD9WpRYpnt4DjAQPWcnGMWLrF/sZM+8lRE8hf9B 4VE0N4ZwrZjMBpL6dylGgQMLsCTqQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvddvkedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpedugfeuleegveffhfegleejhefhtedtgeeileeggfeh fefffeevgeejtdeutefftdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Oct 2021 11:49:29 -0400 (EDT) Message-ID: <36e3e2a5-cf09-61e2-3f12-3ea6d17e3ccd@aklaver.com> Date: Fri, 22 Oct 2021 08:49:28 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: Looking for a doc section that presents the overload selection rules Content-Language: en-US To: Bryn Llewellyn Cc: "David G. Johnston" , pgsql-general list References: <4F35D95E-4974-44FC-AA4B-3F1E94580B82@yugabyte.com> <4f7a9fe8-ea27-e4a3-34ac-f05fcfb7f5c3@aklaver.com> From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/21/21 17:42, Bryn Llewellyn wrote: >> On 21-Oct-2021, at 17:15, Adrian Klaver wrote: >> >> On 10/21/21 15:45, Bryn Llewellyn wrote: >>>> /Adrian Klaver wrote:/ >>>> >>> *Why is there no "date" overload of "to_char()"?* > > You've lost me entirely here, I'm afraid. > > My question was simple: why is there no "to_char ( date, text ) → text" overload? Because there is: to_char ( timestamp with time zone, text ) → text and date is a subset of timestamp(tz) where timestamptz is the preferred form. This allows you to do things like: select '10/30/21 22:00:00'::timestamptz - '10/22/21'::date; ?column? ----------------- 8 days 22:00:00 > > Without this, and as long as the good practice rule is followed to code so that implicit conversion is never invoked, then using "to_char()" on a "date" value requires writing an explicit typecast. There are only two possible choices: cast to plain "timestamp" or cast to "timestamptz". And for reasons that I'm sure you'd explain better than I would, the choice makes no actual difference to the outcome when a template is used that's natural for a "date" value. > > So the consequence is that you have to write cluttered code and a fairly elaborate comment to say what your intention is. Welcome to date/times. As I have said before if you are looking for end to end consistency you are in the wrong place. It is an area where specific comments are needed to explain your choices. I am not understanding the template reference as there is a difference in output between timestamp and timestamptz. > > What would you do here? Would you break the rule of practice so that you simply invoke "to_char()" on a "date" value _without writing a typecast_ and then letting the implicit conversion (which we know is to "timestamptz") have its innocent effect? > Working in timestamptz is a benefit so I'm fine with that being the default. The bottom line is that working correctly with date/times is difficult and requires effort spent studying the underlying structure. More so when you switch between systems e.g. Javascript 0 indexed months. -- Adrian Klaver adrian.klaver@aklaver.com