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

Commit7d23381

Browse files
committed
Remove redundant function calls in timestamp[tz]_part().
The DTK_DOW/DTK_ISODOW and DTK_DOY switch cases in timestamp_part() andtimestamptz_part() contained calls of timestamp2tm() that were fullyredundant with the ones done just above the switch. This evidently creptin during commit258ee1b, which relocated that code from another placewhere the calls were indeed needed. Just delete the redundant calls.I (tgl) noted that our test coverage of these functions left quite abit to be desired, so extend timestamp.sql and timestamptz.sql tocover all the branches.Back-patch to all supported branches, as the previous commit was.There's no real issue here other than some wasted cycles in somenot-too-heavily-used code paths, but the test coverage seems valuable.Report and patch by Li Japin; test case adjustments by me.Discussion:https://postgr.es/m/SG2PR06MB37762CAE45DB0F6CA7001EA9B6550@SG2PR06MB3776.apcprd06.prod.outlook.com
1 parentd94766a commit7d23381

File tree

5 files changed

+693
-395
lines changed

5 files changed

+693
-395
lines changed

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4543,20 +4543,12 @@ timestamp_part(PG_FUNCTION_ARGS)
45434543

45444544
caseDTK_DOW:
45454545
caseDTK_ISODOW:
4546-
if (timestamp2tm(timestamp,NULL,tm,&fsec,NULL,NULL)!=0)
4547-
ereport(ERROR,
4548-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4549-
errmsg("timestamp out of range")));
45504546
result=j2day(date2j(tm->tm_year,tm->tm_mon,tm->tm_mday));
45514547
if (val==DTK_ISODOW&&result==0)
45524548
result=7;
45534549
break;
45544550

45554551
caseDTK_DOY:
4556-
if (timestamp2tm(timestamp,NULL,tm,&fsec,NULL,NULL)!=0)
4557-
ereport(ERROR,
4558-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4559-
errmsg("timestamp out of range")));
45604552
result= (date2j(tm->tm_year,tm->tm_mon,tm->tm_mday)
45614553
-date2j(tm->tm_year,1,1)+1);
45624554
break;
@@ -4747,20 +4739,12 @@ timestamptz_part(PG_FUNCTION_ARGS)
47474739

47484740
caseDTK_DOW:
47494741
caseDTK_ISODOW:
4750-
if (timestamp2tm(timestamp,&tz,tm,&fsec,NULL,NULL)!=0)
4751-
ereport(ERROR,
4752-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4753-
errmsg("timestamp out of range")));
47544742
result=j2day(date2j(tm->tm_year,tm->tm_mon,tm->tm_mday));
47554743
if (val==DTK_ISODOW&&result==0)
47564744
result=7;
47574745
break;
47584746

47594747
caseDTK_DOY:
4760-
if (timestamp2tm(timestamp,&tz,tm,&fsec,NULL,NULL)!=0)
4761-
ereport(ERROR,
4762-
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
4763-
errmsg("timestamp out of range")));
47644748
result= (date2j(tm->tm_year,tm->tm_mon,tm->tm_mday)
47654749
-date2j(tm->tm_year,1,1)+1);
47664750
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp