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 1qHPdp-000193-L8 for pgsql-general@arkaria.postgresql.org; Thu, 06 Jul 2023 14:07:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qHPdo-0005sw-GM for pgsql-general@arkaria.postgresql.org; Thu, 06 Jul 2023 14:07:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHPdo-0005sm-5R for pgsql-general@lists.postgresql.org; Thu, 06 Jul 2023 14:07:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qHPdl-002YKV-MY for pgsql-general@lists.postgresql.org; Thu, 06 Jul 2023 14:07:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 366E7NU11204405; Thu, 6 Jul 2023 10:07:23 -0400 From: Tom Lane To: Ron cc: pgsql-general@lists.postgresql.org Subject: Re: function to_char(unknown) is not unique at character 8 In-reply-to: <937cdcff-5ecd-afdf-8b86-64c0c6c982fa@gmail.com> References: <2f8f581c.67f1.1892a7fba60.Coremail.gzhcoder@126.com> <937cdcff-5ecd-afdf-8b86-64c0c6c982fa@gmail.com> Comments: In-reply-to Ron message dated "Thu, 06 Jul 2023 09:01:43 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1204403.1688652443.1@sss.pgh.pa.us> Date: Thu, 06 Jul 2023 10:07:23 -0400 Message-ID: <1204404.1688652443@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ron writes: > On 7/6/23 04:19, gzh wrote: >> when I execute the sql below , the to_char function caused the following >> error. >> select TO_CHAR('1000000'); > Isn't '1000000' already a character string? Nope; in the mind of the Postgres parser, it's a literal of unknown type, with the actual type to be inferred from context. There is a small preference for resolving such a thing as being of text type, but only a small one. The rules are exactly the same as for an undecorated NULL constant. regards, tom lane