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 1mdenY-0002iB-Up for pgsql-general@arkaria.postgresql.org; Thu, 21 Oct 2021 20:36:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mdenW-0000AC-Vd for pgsql-general@arkaria.postgresql.org; Thu, 21 Oct 2021 20:36:22 +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 1mdenW-0000A3-L1 for pgsql-general@lists.postgresql.org; Thu, 21 Oct 2021 20:36:22 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdenT-0001bG-Ic for pgsql-general@lists.postgresql.org; Thu, 21 Oct 2021 20:36:21 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 8D3A85C01B9; Thu, 21 Oct 2021 16:36:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 21 Oct 2021 16:36:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= message-id:date:mime-version:subject:to:references:from :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=4 eiHrXck1+iwRYO5QXIw8mmE5pr3eNWDkUVKdEvp+hk=; b=TfRmaC2yTE5OyuEHY UeCknr9OFGjoLPsHKk3M3BZOK62rhF+oNYKwMT59MDmwpf7vMIO4KE1LqwOpBCVe lK167pY1lwME3zsMK5nxRcXAhpd5OP+Co1IRYC65pcQqGG6WuJLyCZOzg+0YH7b5 ExQkrrmqQ/wY+NGnSJOvWXHnPLPXwHDfqR8V9x2GKiv+v+UipD3QYG0JfpYkCnk+ cw5n0GZL67cYtfC51yeCr73ZhZF1IZkSA+DI4ipVFW9qefnY3P69u4kHOzfsBcd8 yBjneZNBc7FN0gjpQpi0GxTG2iNnMkmpCLq/7u9R42ypO4gpDPcZ12p56o0Xaa17 DbCGw== 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=4eiHrXck1+iwRYO5QXIw8mmE5pr3eNWDkUVKdEvp+ hk=; b=DZP+N7JLYE8xSo5K0xgG8/j8HHOo2JwU8c0jjZgi76jSHTkl/GpjGVFuY z+QvYmA+u8HWBgwXh9f5D+qGMnkNuRRBmQNVUcgH3PhzHCpz6+wFPWONLkF0k3wO imDywzigui7QwDXmpysWlbO/TXeK0BhcRFTkFdxTdadGKZnK8/ouWT6Gwj6Jlhvi bDdFTmLmZRSeFkE2wLbzoTF65tEKWp4wD0WvW8EzPV4cQwzMPfQpKglx4NTxpvO4 seCjqDo0f+1hVKHH2rv+O8fm7Q+yBOxPFAXF45l+zPXH7CjhojEE2bikldEsuLvh mayNmnmBvGSrZozI8PGdFswDdFFwg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvddviedgudeglecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepleekgeejhfekteehfeduveetheeivdduheekudel teefvdffueehtddvgedtfeefnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrgh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughr ihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 21 Oct 2021 16:36:17 -0400 (EDT) Message-ID: Date: Thu, 21 Oct 2021 13:36:17 -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 , pgsql-general list References: <4F35D95E-4974-44FC-AA4B-3F1E94580B82@yugabyte.com> From: Adrian Klaver In-Reply-To: <4F35D95E-4974-44FC-AA4B-3F1E94580B82@yugabyte.com> 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 12:52, Bryn Llewellyn wrote: > I fear that I'm about to embarrass myself again. So I'll just ask for > forgiveness in advance. > > Here's a simple test to get started. (All tests are done in a session > where I set the timezone to 'UTC'.) > > *drop function if exists f(text)        cascade; > **drop function if exists f(timestamp)   cascade; > **drop function if exists f(timestamptz) cascade; > ** > * > *create function f(t in text) >   returns text >   language plpgsql > as $body$ > begin >   return 'plain "text" overload: '||t; > end; > $body$; > > **select f('2021-03-15'::date); > * > This causes the 42883 error, "function f(date) does not exist". I > might've expected the system to have done an implicit conversion to > "text" because this conversion is supported, thus: > > *select f(('2021-03-15'::date)::text);* > > This succeeds with this result: > > *plain "text" overload: 2021-03-15 > * > There's clearly a rule at work here. For some reason, the implicit > conversion from "date" to "text" is not considered to be acceptable. From 10.3 " Look for the best match. Discard candidate functions for which the input types do not match and cannot be converted (using an implicit conversion) to match. unknown literals are assumed to be convertible to anything for this purpose. If only one candidate remains, use it; else continue to the next step. " See cast query below. > For some reason, the implicit conversion from "date" to "timestamptz" > _is_ considered to be preferable to the implicit conversion from "date" > to plain "timestamp". https://www.postgresql.org/docs/current/catalog-pg-type.html select oid from pg_type where typname = 'date'; oid ------ 1082 https://www.postgresql.org/docs/current/catalog-pg-cast.html select * from pg_cast where castsource = 1082; oid | castsource | casttarget | castfunc | castcontext | castmethod -------+------------+------------+----------+-------------+------------ 11421 | 1082 | 1114 | 2024 | i | f 11422 | 1082 | 1184 | 1174 | i | f Note castcontext of 'i'(implicit) and only to timestamp types per below. select typname, typispreferred from pg_type where oid in (1114, 1184); typname | typispreferred -------------+---------------- timestamp | f timestamptz | t typispreferred has timestmaptz as preferred cast. > > I started with "38.6. Function Overloading", followed the link to > "Chapter 10. Type Conversion" and started with "10.3. Functions". I read > "If no exact match is found, see if the function call appears to be a > special type conversion request…" as far as "Note that the “best > match” rules are identical for operator and function type resolution." > So I went to "10.2. Operators" and searched in the page for "timestamp". > No hits. > > Where, in the PG doc, can I find a statement of the rules that allow me > to predict the outcome of my tests? > -- Adrian Klaver adrian.klaver@aklaver.com