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

docs: update SQLite timestamp_ms example to allow millisecond defaults #448

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

Conversation

woobs
Copy link

@woobs woobs commented Dec 6, 2024

The current SQLite examples for setting the default value for a timestamp_ms column do not include the actual millisecond value of the current time, simply multiplying the UNIX timestamp in seconds by 1000. We can, however, obtain the millisecond value with the 'subsec' modifier to the unixepoch function, which returns a float, which we can cast to an integer value:

select unixepoch() * 1000, unixepoch('subsec'), CAST(unixepoch('subsec') * 1000 as INT);

unixepoch() * 1000 unixepoch('subsec') CAST(unixepoch('subsec') * 1000 as INT)
1733502310000 1733502310.844 1733502310844

One concern is this note from the SQLite Date/Time Function Docs:

The current implemention [sic] increases the resolution from seconds to milliseconds, but this might increase to a higher resolution in future releases of SQLite

But I don't think that would change the output.

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