![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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... |
#3
| |||
| |||
|
|
The following code works in 8.0.4 but fails in 8.1.0: select to_char('1:00 pm'::time,'HH:MM AM'); |
#4
| |||
| |||
|
|
"Nick Addington" <adding (AT) math (DOT) wisc.edu> writes: The following code works in 8.0.4 but fails in 8.1.0: select to_char('1:00 pm'::time,'HH:MM AM'); I'm inclined to think that disallowing AM/PM for intervals was a mistake --- if we allow both HH and HH24 (which we do) then the various flavors of AM/PM seem reasonable to allow as well. Bruce, did you have a specific rationale for that? I notice the code now specifically forces HH to be treated as HH24 in the interval case, which was not so before 8.1; we would need to revert that change as well to continue supporting TIME cases reasonably. |
#5
| |||
| |||
|
|
I see your issue with HH/HH24, but I wanted this to work: test=> select to_char('14 hours'::interval, 'HH'); to_char --------- 14 (1 row) With the HH/HH24 change that is going to return 2. Do interval folks know they would have to use HH24 for intervals? |
|
Should we subtract 12 only if the time is < 24. That also seems strange. Also, a zero hour interval to HH would return 12, not 0. |
#6
| |||
| |||
|
|
Bruce Momjian <pgman (AT) candle (DOT) pha.pa.us> writes: I see your issue with HH/HH24, but I wanted this to work: test=> select to_char('14 hours'::interval, 'HH'); to_char --------- 14 (1 row) With the HH/HH24 change that is going to return 2. Do interval folks know they would have to use HH24 for intervals? Dunno if they know it, but they always had to do it that way before 8.1, so it's not a change to require it. I get this in everything back to 7.2: regression=# select to_char('14 hours'::interval, 'HH'); to_char --------- 02 (1 row) regression=# select to_char('14 hours'::interval, 'HH24'); to_char --------- 14 (1 row) and I don't see anything especially wrong with that behavior, as long as it's documented. Should we subtract 12 only if the time is < 24. That also seems strange. Also, a zero hour interval to HH would return 12, not 0. Offhand I'd vote for making the HH code use a "mod 12" calculation, and making AM/PM depend on the value "mod 24". This gives at least a slightly sane behavior for intervals > 24 hours. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org |
#7
| |||
| |||
|
|
Oh, one more thing. With the new patch I just posted, '0 hours' and 'HH' returns 12: test=> select to_char('0 hours'::interval, 'HH'); to_char --------- 12 (1 row) |
#8
| |||
| |||
|
|
Bruce Momjian <pgman (AT) candle (DOT) pha.pa.us> writes: I see your issue with HH/HH24, but I wanted this to work: test=> select to_char('14 hours'::interval, 'HH'); to_char --------- 14 (1 row) With the HH/HH24 change that is going to return 2. Do interval folks know they would have to use HH24 for intervals? Dunno if they know it, but they always had to do it that way before 8.1, so it's not a change to require it. I get this in everything back to 7.2: regression=# select to_char('14 hours'::interval, 'HH'); to_char --------- 02 (1 row) regression=# select to_char('14 hours'::interval, 'HH24'); to_char --------- 14 (1 row) and I don't see anything especially wrong with that behavior, as long as it's documented. Should we subtract 12 only if the time is < 24. That also seems strange. Also, a zero hour interval to HH would return 12, not 0. Offhand I'd vote for making the HH code use a "mod 12" calculation, and making AM/PM depend on the value "mod 24". This gives at least a slightly sane behavior for intervals > 24 hours. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org |
![]() |
| Thread Tools | |
| Display Modes | |
| |