Search Postgresql Archives

Re: TO_DATE function between PostgreSQL 8.2 and 9.4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Good Morning,

On Tue, May 17, 2022 at 8:55 AM gzh <gzhcoder@xxxxxxx> 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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux