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 1mdyhS-0007eo-Co for pgsql-general@arkaria.postgresql.org; Fri, 22 Oct 2021 17:51:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mdyhR-0000gp-Ar for pgsql-general@arkaria.postgresql.org; Fri, 22 Oct 2021 17:51:25 +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 1mdyhP-0000gg-Co for pgsql-general@lists.postgresql.org; Fri, 22 Oct 2021 17:51:25 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdyhJ-00037O-Uv for pgsql-general@lists.postgresql.org; Fri, 22 Oct 2021 17:51:22 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 178605C00C4; Fri, 22 Oct 2021 13:51:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 22 Oct 2021 13:51:16 -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=fm1; bh=F wi0YhWhVxUakBX8C0iMUOBzr62pYUhU8ls7WJiSB9s=; b=yNkZUr6in+qOe9eNX 5lBzIbIQO6vesGr00Fs3UvZlcBzoo9+9S9sxy28nimsLSedT64O5YU/7bSl9o3/0 QjEY0+9cCsUEOTtXiQPJgBRc2u9v9Fcd7/fXiKuL13oy2+4Jd8sV/pLt03x2h+xF F0vuYIGKmEwzjxVEl33DqNS2dTMz9zWp2rLS0E7DaNgI5Mju/4bOt7DfqcF9BKs7 2LUKbmg6YdhNYHUIX1vwYvrx9YHvi3yTnxGrJ0dEUDFLfU7IXPRcVHUoFcF1YtqN 3942IRqzfLk6yn5wychjXmpN+QKUlxeNhfGlVSJflBK5oGG28Fft3spORbkTte/E +UFPA== 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=Fwi0YhWhVxUakBX8C0iMUOBzr62pYUhU8ls7WJiSB 9s=; b=VZEV0+r7iSYAcK4KG35yGQetmJu733EE3NnzJqN3k8WNDZ5L37Jehh/VV vPM8oa88DtHOVl5V9a2Es5mh7wNdqC/QtfCECE1iuTx9Nu7BE6INopl9h0bRyCZ9 2RV57y2MKmWaOe7GLdqM/1SC/DLI9JuA3T3uTfmhziHfQF0EYHHa0azou/C+rJae EdrlpiKh++78UXwKamWCEKtNOxgS3+/8LwfBk/TV22nYvVaOG9nFKJAU2il/srMw X56W3+Jy23YtsLABJwm0x9OKyoTAnnSl0pCcWfZLQNgWiPXZCPMPHk15szcGuxO4 jZ+x5XdthPMp97aiT7EJx5+axccyg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvddvkedgjedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeevveefveefueegffekkefhgeeiueffgfetueejvdfg hfeujeejhfekjeelgedtgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Oct 2021 13:51:14 -0400 (EDT) Subject: Re: Looking for a doc section that presents the overload selection rules 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> <36e3e2a5-cf09-61e2-3f12-3ea6d17e3ccd@aklaver.com> <476BE5DC-8D86-422B-9463-C41696271A22@yugabyte.com> From: Adrian Klaver Message-ID: <175fcff4-078a-1208-6c57-b197c1e6047a@aklaver.com> Date: Fri, 22 Oct 2021 10:51:13 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <476BE5DC-8D86-422B-9463-C41696271A22@yugabyte.com> 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: Archived-At: Precedence: bulk On 10/22/21 10:26 AM, Bryn Llewellyn wrote: > // > I’ll make this my final turn on this thread. Yes, I accept that > everything to do with the date-time story is tough stuff. And I do > understand that this is, to a large extent, just a reflection of the > fact that the terrain is inevitably affected by genuine > astronomical facts together with the history of technology and human > thought. I accept, too, that the PostgreSQL implementation in this space > is constrained, to some extent, by decisions taken by the SQL Standard > folks, over the years, some of which were arguably questionable. > Then PostgreSQL brings its own quirks (esp. e.g. everything to do with > intervals and their use). So I do see that application code will need a > lot of commenting to make the programmer’s intent clear. > > Having said all this, the following example seems to me to make an > unassailable point: > > deallocate all; > prepare s as > with c as ( >   select >     '2021-06-15'         ::date        as   d, >     '2021-06-15 12:00:00'::timestamp   as   ts, >     '2021-06-15 12:00:00'::timestamptz as tstz) > select >   rpad(current_setting('timezone'), 20)  as "timezone", >   d   ::text, >   ts  ::text, >   tstz::text > from c; > > \t on > set timezone = 'Europe/Helsinki'; > execute s; > > set timezone = 'America/Los_Angeles'; > execute s; > \t > > This is the result: > >  Europe/Helsinki      | 2021-06-15 | 2021-06-15 12:00:00 | 2021-06-15 > 22:00:00+03 > >  America/Los_Angeles  | 2021-06-15 | 2021-06-15 12:00:00 | 2021-06-15 > 12:00:00-07 > > So the “::text” typecast operator understands that “date” values, plain > “timestamp” values, and “timestamptz” values each bear different > information—and it takes account, in each case, only of the relevant > information. > > There could, so easily, have been three “to_char()” overloads for these > three data types that honored the spirit of the “::text” typecast by > rendering only what’s meaningful, despite what the template asks for. I > could write these myself and use “extract()” to get the meaningful > elements, and only these, before rendering them, silently refusing the > request to render meaningless fields. Why? You asked for information in the template that is available and it provides it. It does not seem to be that out of line. From different realm(Python): from datetime import date today_date = date.today() print(today_date) 2021-10-22 today_date.strftime('%c') 'Fri Oct 22 00:00:00 2021' It might also be useful to know that to_char() and friends are modeled after the Oracle ones: src/backend/utils/adt/formatting.c The PostgreSQL routines for a timestamp/int/float/numeric formatting, inspired by the Oracle TO_CHAR() / TO_DATE() / TO_NUMBER() routines. > > However, reality is different. “to_char()” uses defaults when the value > at hand doesn’t represent these and then renders them as the template > specifies. > > prepare s as > with c as ( >   select >     '2021-06-15 12:00:00'::text as t, >     'dd-Mon-yyyy TZH:TZM'       as fmt) > select >   to_char(t::timestamp,   fmt) as "plain timestamp", >   to_char(t::timestamptz, fmt) as "timestamptz" > from c; > > This always shows the “TZH:TZM” component of the plain “timestamp” as > “00:00”. And for the “timestamptz” value, it shows this to reflect the > session’s timezone setting. > > This informs what you get when you want to render a “date” value—and how > to code it. Of course, when I do this, I wouldn’t ask to see time-of-day > or timezone fields. So fair enough, I suppose. Anyway, so it is—and so > it ever will be. > > > > > > > > > > -- Adrian Klaver adrian.klaver@aklaver.com