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

Commit78aef14

Browse files
committed
Fix time_part and timetz_part (ie, EXTRACT() for those datatypes) to
include a fractional part in the output for MILLISECOND and SECOND cases,rather than truncating the source value. This is what the float-timestampcode has always done, and it was clearly the code author's intent to dothe same for integer timestamps, but he forgot about integer division in C.The other datatypes supported by EXTRACT() already do this correctly.Backpatch to 8.4, so that the default (integer) behavior of that branch willmatch the default (float) behavior of older branches. Arguably we shouldpatch further back, but it's possible that applications are expecting thebroken behavior in older branches. 8.4 is new enough that expectationsshouldn't be too settled.Per report from Greg Stark.
1 parent25d9bf2 commit78aef14

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.146 2009/06/11 14:49:03 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.147 2009/07/29 22:19:18 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1701,23 +1701,23 @@ time_part(PG_FUNCTION_ARGS)
17011701
{
17021702
caseDTK_MICROSEC:
17031703
#ifdefHAVE_INT64_TIMESTAMP
1704-
result=tm->tm_sec*USECS_PER_SEC+fsec;
1704+
result=tm->tm_sec*1000000.0+fsec;
17051705
#else
17061706
result= (tm->tm_sec+fsec)*1000000;
17071707
#endif
17081708
break;
17091709

17101710
caseDTK_MILLISEC:
17111711
#ifdefHAVE_INT64_TIMESTAMP
1712-
result=tm->tm_sec*INT64CONST(1000)+fsec /INT64CONST(1000);
1712+
result=tm->tm_sec*1000.0+fsec /1000.0;
17131713
#else
17141714
result= (tm->tm_sec+fsec)*1000;
17151715
#endif
17161716
break;
17171717

17181718
caseDTK_SECOND:
17191719
#ifdefHAVE_INT64_TIMESTAMP
1720-
result=tm->tm_sec+fsec /USECS_PER_SEC;
1720+
result=tm->tm_sec+fsec /1000000.0;
17211721
#else
17221722
result=tm->tm_sec+fsec;
17231723
#endif
@@ -2469,23 +2469,23 @@ timetz_part(PG_FUNCTION_ARGS)
24692469

24702470
caseDTK_MICROSEC:
24712471
#ifdefHAVE_INT64_TIMESTAMP
2472-
result=tm->tm_sec*USECS_PER_SEC+fsec;
2472+
result=tm->tm_sec*1000000.0+fsec;
24732473
#else
24742474
result= (tm->tm_sec+fsec)*1000000;
24752475
#endif
24762476
break;
24772477

24782478
caseDTK_MILLISEC:
24792479
#ifdefHAVE_INT64_TIMESTAMP
2480-
result=tm->tm_sec*INT64CONST(1000)+fsec /INT64CONST(1000);
2480+
result=tm->tm_sec*1000.0+fsec /1000.0;
24812481
#else
24822482
result= (tm->tm_sec+fsec)*1000;
24832483
#endif
24842484
break;
24852485

24862486
caseDTK_SECOND:
24872487
#ifdefHAVE_INT64_TIMESTAMP
2488-
result=tm->tm_sec+fsec /USECS_PER_SEC;
2488+
result=tm->tm_sec+fsec /1000000.0;
24892489
#else
24902490
result=tm->tm_sec+fsec;
24912491
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp