Skip to content

feat: SELECT non-deterministic transaction-time rewrites - #1713

Merged
jkaczman merged 3 commits into
mainfrom
jk-nd-selects
Oct 2, 2026
Merged

jkaczman merged 3 commits into
mainfrom
jk-nd-selects

Conversation

@jkaczman

@jkaczman jkaczman commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

#1541 + #1568 introduced support to re-write date-time functions, which are inconsistent when executed multiple times. This included maintaining a consistent now() start time in a transaction for INSERT statements.

This extends on that support by now also re-writing SELECT statements that include these transaction start-time based functions.

This includes handling an interesting case, where if a SELECT now() query is sent, and we re-write it before sending to Postgres, the client still must receive the response under the correct column name (in that case, the column name would be now). To handle that, this checks if there's a ResTarget node that has no name with FuncCall inner-value (that's transaction time based). If there is, it sets the ResTarget name to the column name that would've been returned as part of the re-write.

This also includes some light refactoring to split transaction-time SELECT re-writes vs. INSERT re-writes into two files.

This does not address coverage for UPDATE / DELETE / etc.

Fixes #1624.

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

if nd_function_rewrite {
match stmt.stmt_mut() {
NodeMut::InsertStmt(_) => {
// TODO: we could also support UPDATE / etc

@levkk levkk Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: UPDATE would be good - similar mechanics to SELECT: find and replace calls to now() and current_timestamp(). Totally fine to do as a follow up.

@jkaczman
jkaczman added this pull request to the merge queue Oct 2, 2026
Merged via the queue into main with commit 1979e16 Oct 2, 2026
72 of 74 checks passed
@jkaczman
jkaczman deleted the jk-nd-selects branch October 2, 2026 09:46
github-merge-queue Bot pushed a commit that referenced this pull request Oct 2, 2026
Follow-up to #1713 to also handle re-writing UPDATE statements when a
date-time function based on the transaction start time is present.
Re-uses the same transform code as SELECT.
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.

Rewrite ND transaction-time functions in SELECT as well

2 participants