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