aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/utils/adt/timestamp.c7
-rw-r--r--src/test/regress/expected/timestamp.out2
-rw-r--r--src/test/regress/expected/timestamptz.out2
3 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index eb954847267..4b8d52ef7ba 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -4265,6 +4265,7 @@ date2isoweek(int year, int mon, int mday)
/* date2isoyear()
*
* Returns ISO 8601 year number.
+ * Note: zero or negative results follow the year-zero-exists convention.
*/
int
date2isoyear(int year, int mon, int mday)
@@ -4539,6 +4540,9 @@ timestamp_part(PG_FUNCTION_ARGS)
case DTK_ISOYEAR:
result = date2isoyear(tm->tm_year, tm->tm_mon, tm->tm_mday);
+ /* Adjust BC years */
+ if (result <= 0)
+ result -= 1;
break;
case DTK_DOW:
@@ -4735,6 +4739,9 @@ timestamptz_part(PG_FUNCTION_ARGS)
case DTK_ISOYEAR:
result = date2isoyear(tm->tm_year, tm->tm_mon, tm->tm_mday);
+ /* Adjust BC years */
+ if (result <= 0)
+ result -= 1;
break;
case DTK_DOW:
diff --git a/src/test/regress/expected/timestamp.out b/src/test/regress/expected/timestamp.out
index ce5e06c9185..3ff048983d1 100644
--- a/src/test/regress/expected/timestamp.out
+++ b/src/test/regress/expected/timestamp.out
@@ -822,7 +822,7 @@ SELECT d1 as "timestamp",
Fri Feb 14 17:32:01 1997 | 1997 | 7 | 5 | 5 | 45
Sat Feb 15 17:32:01 1997 | 1997 | 7 | 6 | 6 | 46
Sun Feb 16 17:32:01 1997 | 1997 | 7 | 7 | 0 | 47
- Tue Feb 16 17:32:01 0097 BC | -96 | 7 | 2 | 2 | 47
+ Tue Feb 16 17:32:01 0097 BC | -97 | 7 | 2 | 2 | 47
Sat Feb 16 17:32:01 0097 | 97 | 7 | 6 | 6 | 47
Thu Feb 16 17:32:01 0597 | 597 | 7 | 4 | 4 | 47
Tue Feb 16 17:32:01 1097 | 1097 | 7 | 2 | 2 | 47
diff --git a/src/test/regress/expected/timestamptz.out b/src/test/regress/expected/timestamptz.out
index 68c64843bb0..80d62ee658c 100644
--- a/src/test/regress/expected/timestamptz.out
+++ b/src/test/regress/expected/timestamptz.out
@@ -913,7 +913,7 @@ SELECT d1 as timestamptz,
Fri Feb 14 17:32:01 1997 PST | 1997 | 7 | 5 | 5 | 45
Sat Feb 15 17:32:01 1997 PST | 1997 | 7 | 6 | 6 | 46
Sun Feb 16 17:32:01 1997 PST | 1997 | 7 | 7 | 0 | 47
- Tue Feb 16 17:32:01 0097 PST BC | -96 | 7 | 2 | 2 | 47
+ Tue Feb 16 17:32:01 0097 PST BC | -97 | 7 | 2 | 2 | 47
Sat Feb 16 17:32:01 0097 PST | 97 | 7 | 6 | 6 | 47
Thu Feb 16 17:32:01 0597 PST | 597 | 7 | 4 | 4 | 47
Tue Feb 16 17:32:01 1097 PST | 1097 | 7 | 2 | 2 | 47