fix: evaluate CURRENT_TIMESTAMP at runtime, not compile time#2
Merged
glommer merged 1 commit intoMay 18, 2026
Merged
Conversation
Owner
|
Sorry it took me a while to get to this =( |
… not compile time
ec68e11 to
a519574
Compare
Contributor
Author
|
@glommer No worries! Rebased on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog
CURRENT_TIMESTAMP,CURRENT_DATE, andCURRENT_TIMEare now evaluated at execution time viaInsn::Functioninstead of being baked into staticString8instructions at compile timenow()as a function alias fordatetime(), matching PostgreSQL behavioruse crate::functions::datetimeimport fromexpr.rsContext
When using pgmicro as the database backend for a web application,
INSERTstatements withDEFAULT CURRENT_TIMESTAMPcolumns and prepared queries referencingCURRENT_TIMESTAMPreturned stale values from statement preparation time rather than execution time.The root cause:
translate_literal()incore/translate/expr.rscalledexec_datetime_full(&[])during compilation and emitted the result as a constant string. The datetime runtime functions already handle zero arguments correctly by callingset_to_current()— the fix is simply to emitInsn::Functioncalls instead of pre-computing the value.Testing and Deployment
6 new sqltests added to
testing/sqltests/tests/scalar-functions-datetime.sqltest. All 8650 passing sqltests still pass (8 pre-existing hash-join mismatches unrelated).