Re: BUG #2056: to_char no long takes time as input? - Mailing list pgsql-bugs

From Michael Fuhr
Subject Re: BUG #2056: to_char no long takes time as input?
Date
Msg-id 20051120090714.GA32592@winnie.fuhr.org
Whole thread Raw
In response to BUG #2056: to_char no long takes time as input?  ("Nick Addington" <adding@math.wisc.edu>)
List pgsql-bugs
On Sun, Nov 20, 2005 at 07:53:50AM +0000, Nick Addington wrote:
> The following code works in 8.0.4 but fails in 8.1.0:
>
> select to_char('1:00 pm'::time,'HH:MM AM');
>
> 8.1.0 gives this is the error message:
> ERROR:  invalid format specification for an interval value
> HINT:  Intervals are not tied to specific calendar dates.
>
> I saw some discussion on the -hackers list about deprecating
> to_char(interval, text), but do you really want to chuck to_char(time,
> text)?  That's a useful function.  Or at least, I was using it...

to_char(time,text) doesn't exist, at least not in 7.3 and later --
you can see that with "\df to_char" in psql.  If you set debug_print_parse
to on and set client_min_messages to debug1, you'll see that the
function being called is funcid 1768, which is

test=> select 1768::regprocedure;
      regprocedure
------------------------
 to_char(interval,text)
(1 row)

You'll also see that this function's first argument is a function
expression with funcid 1370, which is

test=> select 1370::regprocedure;
            regprocedure
------------------------------------
 "interval"(time without time zone)
(1 row)

So the time value is first converted to an interval and then passed
to to_char(interval,text).

test=> select "interval"('1:00 pm'::time);
 interval
----------
 13:00:00
(1 row)

test=> select to_char('13:00:00'::interval,'HH:MM AM');
ERROR:  invalid format specification for an interval value
HINT:  Intervals are not tied to specific calendar dates.

This looks like the commit that changed the behavior in 8.1 (the
hint was added later):

http://archives.postgresql.org/pgsql-committers/2005-08/msg00200.php

--
Michael Fuhr

pgsql-bugs by date:

Previous
From: "Nick Addington"
Date:
Subject: BUG #2056: to_char no long takes time as input?
Next
From: "Magnus Hagander"
Date:
Subject: Re: BUG #2042: Installation failed