Re: TO_DATE function between PostgreSQL 8.2 and 9.4

From: John W Higgins <wishdev(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: TO_DATE function between PostgreSQL 8.2 and 9.4
Date: 2022-05-17 16:23:05
Message-ID: CAPhAwGwjLwyymUygv92hmkt1LsLi-Jf5apd318rrypk2QCoMVQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Good Morning,

On Tue, May 17, 2022 at 8:55 AM gzh <gzhcoder(at)126(dot)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;

(see https://www.db-fiddle.com/f/w5WYLgsiFLv3jm7hhJ7dsH/0 for a working
example)

John

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2022-05-17 16:58:49 Re: TO_DATE function between PostgreSQL 8.2 and 9.4
Previous Message David G. Johnston 2022-05-17 16:22:44 Re: TO_DATE function between PostgreSQL 8.2 and 9.4