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

Commit1a3efa1

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 parent26ae3aa commit1a3efa1

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
@@ -4373,6 +4373,7 @@ date2isoweek(int year, int mon, int mday)
43734373
/* date2isoyear()
43744374
*
43754375
*Returns ISO 8601 year number.
4376+
*Note: zero or negative results follow the year-zero-exists convention.
43764377
*/
43774378
int
43784379
date2isoyear(intyear,intmon,intmday)
@@ -4647,6 +4648,9 @@ timestamp_part(PG_FUNCTION_ARGS)
46474648

46484649
caseDTK_ISOYEAR:
46494650
result=date2isoyear(tm->tm_year,tm->tm_mon,tm->tm_mday);
4651+
/* Adjust BC years */
4652+
if (result <=0)
4653+
result-=1;
46504654
break;
46514655

46524656
caseDTK_DOW:
@@ -4843,6 +4847,9 @@ timestamptz_part(PG_FUNCTION_ARGS)
48434847

48444848
caseDTK_ISOYEAR:
48454849
result=date2isoyear(tm->tm_year,tm->tm_mon,tm->tm_mday);
4850+
/* Adjust BC years */
4851+
if (result <=0)
4852+
result-=1;
48464853
break;
48474854

48484855
caseDTK_DOW:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ SELECT d1 as "timestamp",
809809
Fri Feb 14 17:32:01 1997 | 1997 | 7 | 5 | 5 | 45
810810
Sat Feb 15 17:32:01 1997 | 1997 | 7 | 6 | 6 | 46
811811
Sun Feb 16 17:32:01 1997 | 1997 | 7 | 7 | 0 | 47
812-
Tue Feb 16 17:32:01 0097 BC | -96 | 7 | 2 | 2 | 47
812+
Tue Feb 16 17:32:01 0097 BC | -97 | 7 | 2 | 2 | 47
813813
Sat Feb 16 17:32:01 0097 | 97 | 7 | 6 | 6 | 47
814814
Thu Feb 16 17:32:01 0597 | 597 | 7 | 4 | 4 | 47
815815
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
@@ -918,7 +918,7 @@ SELECT d1 as timestamptz,
918918
Fri Feb 14 17:32:01 1997 PST | 1997 | 7 | 5 | 5 | 45
919919
Sat Feb 15 17:32:01 1997 PST | 1997 | 7 | 6 | 6 | 46
920920
Sun Feb 16 17:32:01 1997 PST | 1997 | 7 | 7 | 0 | 47
921-
Tue Feb 16 17:32:01 0097 PST BC | -96 | 7 | 2 | 2 | 47
921+
Tue Feb 16 17:32:01 0097 PST BC | -97 | 7 | 2 | 2 | 47
922922
Sat Feb 16 17:32:01 0097 PST | 97 | 7 | 6 | 6 | 47
923923
Thu Feb 16 17:32:01 0597 PST | 597 | 7 | 4 | 4 | 47
924924
Tue Feb 16 17:32:01 1097 PST | 1097 | 7 | 2 | 2 | 47

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp