-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customize UUIDv7 generation for database partitioning #130843
Comments
For this one, I plan to somehow make it work under #120878. I don't know how to make it work properly though because the notion of |
As for |
Using a timestamp would be okay, but the users’ mindset for this function (or at least for my use case ;-)) is "I need to create a new DB partition for today / the next month which is YYYY-MM-DD 0 o'clock. Gimme the minimal UUIDv7 for that!", so supporting datetimes would be very convenient. |
It's possible to convert the datetime object to a timestaml via .timestamp(). One reason for accepting a timestamp is essentially to make the interface more flexible for the standard library and easier to maintain (maintenance cost is something that needs to be taken into account). Also, a timestamp is timezone agnostic. I'm leaving for 10 days so I won't be able to reply except on mobile. |
I understand your reasoning and something with a timestamp is better than nothing. :-) |
We actually had a similar discussion on whether to accept or not datetime objects for gzip in #128584. I see reasons not to but I also see reasons to. I think we need to find an equilibrium between what would be the most useful and what would be the best solution for future compatibility (remember that once we decide on something for the standard library, it becomes kind of "frozen" and requires a deprecation period for any changes we make). |
It is enough to take the left segment of the required length from the UUID as the partition key. The accuracy does not necessarily have to be exactly the same as 24 hours. |
Nobody really needs version 6. Only version 1 and 7. See the uuid_extract_timestamp() function here for an example |
You still need to pass in a custom timestamp/datetime to calculate that segment for the given time and in advance. |
Feature or enhancement
Proposal:
Support for UUIDv7 via
uuid7()
has just landed inmain
: #89083One use-case for UUIDv7 is using it as PK in databases. Since it is time based, it can also be used as partition key (e.g., to use one partion for each day). In order to calculate the partition range, you need calculate the "minimal" UUID for a given date (i.e.,
2025-04-05 00:00:00
and use all zeros for the random bits =>0196033f-4400-7000-8000-000000000000
).I'm totally fine with
uuid.uuid7()
not taking any arguments, but it would be cool if the building blocks for generating a UUIDv7 based on customunix_ts_ms
,counter
, andtail
could be exposed as well.Another useful addition might be a helper that recovers the original datetime/timestamp from a UUIDv7. I understand that this is additional code that might be slightly out of context, but such functions - like
uuid7()
- would probably not need to be changed, but are not trivial to implement for "normal users".These functions could look like this:
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered: