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 1prIAb-0004mH-3a for pgsql-general@arkaria.postgresql.org; Tue, 25 Apr 2023 12:53:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1prIAZ-0001xe-Sv for pgsql-general@arkaria.postgresql.org; Tue, 25 Apr 2023 12:53:19 +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 1prIAZ-0001xU-Hr for pgsql-general@lists.postgresql.org; Tue, 25 Apr 2023 12:53:19 +0000 Received: from mout-u-204.mailbox.org ([2001:67c:2050:101:465::204]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1prIAW-001obE-W5 for pgsql-general@lists.postgresql.org; Tue, 25 Apr 2023 12:53:18 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4Q5MP26THxz9sq4; Tue, 25 Apr 2023 14:53:10 +0200 (CEST) Date: Tue, 25 Apr 2023 14:53:09 +0200 (CEST) From: Erik Wienhold To: gzh , Tom Lane Cc: pgsql-general@lists.postgresql.org Message-ID: <1073908593.624606.1682427189969@office.mailbox.org> In-Reply-To: <5027d9b9.7aad.187b831fb18.Coremail.gzhcoder@126.com> References: <328d2a0.828a.18799afd0ac.Coremail.gzhcoder@126.com> <1597875806.606392.1681915893771@office.mailbox.org> <70c95d95.7a58.1879a77ed4f.Coremail.gzhcoder@126.com> <2993958.1681924695@sss.pgh.pa.us> <5027d9b9.7aad.187b831fb18.Coremail.gzhcoder@126.com> Subject: Re: psql:t_mstr.sql:994: ERROR: function to_char(numeric) does not exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Normal X-Rspamd-Queue-Id: 4Q5MP26THxz9sq4 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 25/04/2023 13:34 CEST gzh wrote: > > >The solution is the same whether you upgrade or not: you need > >to adjust your search_path to include the "oracle" schema, > >or else explicitly qualify references to orafce functions. > Thank you very much for your help. > > To use the to_date functions of Orafce 3.0.1, we created the following > to_date function in the public schema of the old database. > > ----- > CREATE OR REPLACE FUNCTION to_date(str text) RETURNS date AS $$ SELECT $1= ::date; $$ LANGUAGE sql IMMUTABLE STRICT; COMMENT ON FUNCTION public.to_dat= e(text) IS 'Convert string to date'; > ----- > > To avoid using a to_date function with the same name and parameter in the > pg_catalog schema first, the search_path of the old database is set as > follows: > > "$user", public, pg_catalog > > Make sure that public is searched before pg_catalog. > After the database is upgraded, in order to solve the changes in Oracle > 3.24, we have added oracle schema to the search_path, as shown below=EF= =BC=9A > > "$user", public, oracle, pg_catalog > > The following error occurred when I ran my application. > > 42P13:ERROR:42P13: return type mismatch in function declared to return > pg_catalog.date > > When I put the oracle schema at the end of the search_path, the problem w= as > solved. > The search_path settings without problems are as follows: > > "$user", public, pg_catalog, oracle > > Why does it report an error when i put oracle between public and pg_catal= og? When you created function to_date(text) your search_path was probably =09"$user", public, pg_catalog Thereby the function was created with return type pg_catalog.date and witho= ut a search_path setting. The cast to date in the function body, however, is unqualified and thus rel= ies on the session search_path. When adding oracle to the session search_path before pg_catalog, the cast will be to oracle.date (orafce defines its own date type) instead of pg_catalog.date. The function return type, however, = is still declared as pg_catalog.date. To fix this create the function with an explicit search_path, i.e. =09CREATE FUNCTION to_date(text) =09 RETURNS oracle.date =09 SET search_path =3D oracle =09 ... Or write the cast as $1::oracle.date to not rely on the search_path at all. -- Erik