Skip to content

Commit 37265ca

Browse files
Fix constant when extracting timestamp from UUIDv7.
When extracting a timestamp from a UUIDv7, a conversion from milliseconds to microseconds was using the incorrect constant NS_PER_US instead of US_PER_MS. Although both constants have the same value, this fix improves code clarity by using the semantically correct constant. Backpatch to v18, where UUIDv7 was introduced. Author: Erik Nordström <[email protected]> Reviewed-by: Andrey Borodin <[email protected]> Reviewed-by: Masahiko Sawada <[email protected]> Discussion: https://postgr.es/m/CACAa4V+i07eaP6h4MHNydZeX47kkLPwAg0sqe67R=M5tLdxNuQ@mail.gmail.com Backpatch-through: 18
1 parent 2e2e7ff commit 37265ca

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/backend/utils/adt/uuid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ uuid_extract_timestamp(PG_FUNCTION_ARGS)
748748
+ (((uint64) uuid->data[0]) << 40);
749749

750750
/* convert ms to us, then adjust */
751-
ts = (TimestampTz) (tms * NS_PER_US) -
751+
ts = (TimestampTz) (tms * US_PER_MS) -
752752
(POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY * USECS_PER_SEC;
753753

754754
PG_RETURN_TIMESTAMPTZ(ts);

0 commit comments

Comments
 (0)