Patch of 2004-03-30 corrected date_part(timestamp) for extracting
authorTom Lane <[email protected]>
Sat, 20 Nov 2004 22:12:44 +0000 (22:12 +0000)
committerTom Lane <[email protected]>
Sat, 20 Nov 2004 22:12:44 +0000 (22:12 +0000)
the year from a BC date, but failed to make the same fix in
date_part(timestamptz).

src/backend/utils/adt/timestamp.c

index 4fe4cef7e7162aed053a7c88bcd5f35b08fc7702..f112dbf4532ee28bb17d8e241d92ce544a3f74ab 100644 (file)
@@ -3534,7 +3534,11 @@ timestamptz_part(PG_FUNCTION_ARGS)
                                break;
 
                        case DTK_YEAR:
-                               result = tm->tm_year;
+                               if (tm->tm_year > 0)
+                                       result = tm->tm_year;
+                               else
+                                       /* there is no year 0, just 1 BC and 1 AD */
+                                       result = tm->tm_year - 1;
                                break;
 
                        case DTK_DECADE: