Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit332584d

Browse files
committed
Fix EXTRACT(ISOYEAR FROM timestamp) for years BC.
The test cases added by commit26ae3aa exposed an old oversight intimestamp[tz]_part: they didn't correct the result of date2isoyear()for BC years, so that we produced an off-by-one answer for such years.Fix that, and back-patch to all supported branches.Discussion:https://postgr.es/m/SG2PR06MB37762CAE45DB0F6CA7001EA9B6550@SG2PR06MB3776.apcprd06.prod.outlook.com
1 parent7d23381 commit332584d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

‎src/backend/utils/adt/timestamp.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4265,6 +4265,7 @@ date2isoweek(int year, int mon, int mday)
42654265
/* date2isoyear()
42664266
*
42674267
*Returns ISO 8601 year number.
4268+
*Note: zero or negative results follow the year-zero-exists convention.
42684269
*/
42694270
int
42704271
date2isoyear(intyear,intmon,intmday)
@@ -4539,6 +4540,9 @@ timestamp_part(PG_FUNCTION_ARGS)
45394540

45404541
caseDTK_ISOYEAR:
45414542
result=date2isoyear(tm->tm_year,tm->tm_mon,tm->tm_mday);
4543+
/* Adjust BC years */
4544+
if (result <=0)
4545+
result-=1;
45424546
break;
45434547

45444548
caseDTK_DOW:
@@ -4735,6 +4739,9 @@ timestamptz_part(PG_FUNCTION_ARGS)
47354739

47364740
caseDTK_ISOYEAR:
47374741
result=date2isoyear(tm->tm_year,tm->tm_mon,tm->tm_mday);
4742+
/* Adjust BC years */
4743+
if (result <=0)
4744+
result-=1;
47384745
break;
47394746

47404747
caseDTK_DOW:

‎src/test/regress/expected/timestamp.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ SELECT d1 as "timestamp",
822822
Fri Feb 14 17:32:01 1997 | 1997 | 7 | 5 | 5 | 45
823823
Sat Feb 15 17:32:01 1997 | 1997 | 7 | 6 | 6 | 46
824824
Sun Feb 16 17:32:01 1997 | 1997 | 7 | 7 | 0 | 47
825-
Tue Feb 16 17:32:01 0097 BC | -96 | 7 | 2 | 2 | 47
825+
Tue Feb 16 17:32:01 0097 BC | -97 | 7 | 2 | 2 | 47
826826
Sat Feb 16 17:32:01 0097 | 97 | 7 | 6 | 6 | 47
827827
Thu Feb 16 17:32:01 0597 | 597 | 7 | 4 | 4 | 47
828828
Tue Feb 16 17:32:01 1097 | 1097 | 7 | 2 | 2 | 47

‎src/test/regress/expected/timestamptz.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ SELECT d1 as timestamptz,
913913
Fri Feb 14 17:32:01 1997 PST | 1997 | 7 | 5 | 5 | 45
914914
Sat Feb 15 17:32:01 1997 PST | 1997 | 7 | 6 | 6 | 46
915915
Sun Feb 16 17:32:01 1997 PST | 1997 | 7 | 7 | 0 | 47
916-
Tue Feb 16 17:32:01 0097 PST BC | -96 | 7 | 2 | 2 | 47
916+
Tue Feb 16 17:32:01 0097 PST BC | -97 | 7 | 2 | 2 | 47
917917
Sat Feb 16 17:32:01 0097 PST | 97 | 7 | 6 | 6 | 47
918918
Thu Feb 16 17:32:01 0597 PST | 597 | 7 | 4 | 4 | 47
919919
Tue Feb 16 17:32:01 1097 PST | 1097 | 7 | 2 | 2 | 47

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp