Skip to content
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

Fix volatility of conversion functions #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkindahl
Copy link

@mkindahl mkindahl commented Jun 1, 2024

Function uuid_v7_to_timestamptz can be immutable since given an UUID it will return the same value for eternity regardless of timezone (the returned values will compare equal regardless of the timezone).

Function uuid_timestamptz_to_v7 can be immutable since given a timestamp with a timezone it is ok to return the same random "filler" for each invocation since the random value cannot be reliabily used for anything and there is no requirement that each invocation have to return a different value.

This commit also adds a uuid_timestamptz_to_v7_stable for those cases where a stable value is required, that is, when executions in different queries have to return a different value.

Function `uuid_v7_to_timestamptz` can be immutable since given an UUID
it will return the same value for eternity regardless of timezone (the
returned values will compare equal regardless of the timezone).

Function `uuid_timestamptz_to_v7` can be immutable since given a
timestamp with a timezone it is ok to return the same random "filler"
for each invocation since the random value cannot be reliabily used for
anything and there is no requirement that each invocation have to
return a different value.

This commit also adds a `uuid_timestamptz_to_v7_stable` for those cases
where a stable value is required, that is, when executions in different
queries have to return a different value.
@mkindahl
Copy link
Author

mkindahl commented Jun 1, 2024

This pull request is provided as a proposal for how you can support both an efficient version of the conversion functions as well as providing the ability to generate different v7 UUID for the same timestamp in different queries, where that is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant