Re: TO_DATE function between PostgreSQL 8.2 and 9.4 - Mailing list pgsql-general

From John W Higgins
Subject Re: TO_DATE function between PostgreSQL 8.2 and 9.4
Date
Msg-id CAPhAwGwjLwyymUygv92hmkt1LsLi-Jf5apd318rrypk2QCoMVQ@mail.gmail.com
Whole thread Raw
In response to TO_DATE function between PostgreSQL 8.2 and 9.4  (gzh <gzhcoder@126.com>)
Responses Re: TO_DATE function between PostgreSQL 8.2 and 9.4
List pgsql-general
Good Morning,

On Tue, May 17, 2022 at 8:55 AM gzh <gzhcoder@126.com> wrote:

Hi,

 

--------------------------------------------------------------------------------

ERROR:  function to_date(timestamp with time zone, unknown) does not exist

LINE 1: SELECT to_date(now() + '-7day', 'YYYY-MM-DD')

                ^

********** Error **********


Of course, the most reliable way to deal with it is to 

rewrite the application or SQL to handle types strictly, 

but the application is large and rewrite is a terrible job. 


Is there any easy way to maintain compatibility?


Just create the missing function

create function to_date(timestamp with time zone, text) RETURNS text AS
   'SELECT to_date($1::text, $2)::text'
   LANGUAGE SQL
   IMMUTABLE;


John

pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: TO_DATE function between PostgreSQL 8.2 and 9.4
Next
From: Thomas Kellerer
Date:
Subject: Re: TO_DATE function between PostgreSQL 8.2 and 9.4