Skip to content

fix: evaluate CURRENT_TIMESTAMP at runtime, not compile time#2

Merged
glommer merged 1 commit into
glommer:masterfrom
0xhsn:fix/current-timestamp-prepared-stmts
May 18, 2026
Merged

fix: evaluate CURRENT_TIMESTAMP at runtime, not compile time#2
glommer merged 1 commit into
glommer:masterfrom
0xhsn:fix/current-timestamp-prepared-stmts

Conversation

@0xhsn

@0xhsn 0xhsn commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Changelog

  • CURRENT_TIMESTAMP, CURRENT_DATE, and CURRENT_TIME are now evaluated at execution time via Insn::Function instead of being baked into static String8 instructions at compile time
  • Added now() as a function alias for datetime(), matching PostgreSQL behavior
  • Removed unused use crate::functions::datetime import from expr.rs

Context

When using pgmicro as the database backend for a web application, INSERT statements with DEFAULT CURRENT_TIMESTAMP columns and prepared queries referencing CURRENT_TIMESTAMP returned stale values from statement preparation time rather than execution time.

The root cause: translate_literal() in core/translate/expr.rs called exec_datetime_full(&[]) during compilation and emitted the result as a constant string. The datetime runtime functions already handle zero arguments correctly by calling set_to_current() — the fix is simply to emit Insn::Function calls 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).

@glommer

glommer commented Apr 14, 2026

Copy link
Copy Markdown
Owner

Sorry it took me a while to get to this =(
I have just merged a new release of Turso into pgmicro, and fixed some edges. now() and the other functions are working in the master branch now. But the CURRENT_TIMESTAMP issue is still not resolved. Do you want to update the PR with it ?

@0xhsn 0xhsn force-pushed the fix/current-timestamp-prepared-stmts branch from ec68e11 to a519574 Compare May 15, 2026 22:39
@0xhsn

0xhsn commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

@glommer No worries! Rebased on master, kept just the CURRENT_TIMESTAMP/CURRENT_DATE/CURRENT_TIME runtime-eval fix in core/translate/expr.rs (now emits Insn::Function instead of compile-time Insn::String8), and dropped the now() alias since the PG translator already handles it.

@glommer glommer merged commit 3a97846 into glommer:master May 18, 2026
9 of 10 checks passed
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.

2 participants