Skip to content

feat: re-write date/time functions (calls + DEFAULT) in omni inserts - #1541

Merged
jkaczman merged 10 commits into
mainfrom
jk-use-proxy-time
Sep 16, 2026
Merged

jkaczman merged 10 commits into
mainfrom
jk-use-proxy-time

Conversation

@jkaczman

@jkaczman jkaczman commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

When we perform an INSERT into an omnisharded table, right now, the functions within the statement (or COLUMN_DEFAULT in the table schema) are executed separately on each shard. In the case of time/date functions, this means that they will drift slightly apart, as their execution time will not be the exact same.

To fix this, this PR re-writes all those time/date functions (Postgres ref), specifically: current_date, current_time, current_timestamp, clock_timestamp, localtime, localtimestamp, now, statement_timestamp, timeofday, and transaction_timestamp.

It handles both calls within a VALUES list, as well as is compatible with functions specified within COLUMN_DEFAULT in the table schema. It's also compatible with simple protocol, extended protocol, and prepare/execute.

Refactoring

  • Pushed TransactionType into a Transaction type, so that the time the transaction started could be saved for use with now() / other functions that rely on transaction start time.
  • Created a PreparedPlan type to encapsulate everything the PreparedStatement cache stores for Prepare statements (instead of passing around separate fields in a tuple).
  • Pushed GeneratedId and its corresponding parameter number into a GeneratedParam type.

Shortfalls:

  • If the client specified a timezone, it only works with strings like "UTC" and "America/New_York"; Postgres supports other types such as INTERVAL '-08:00' HOUR TO MINUTE. Right now it errors to prevent incorrect behavior falling through. We previously didn't support any kind of timezone parsing whatsoever.

Docs: pgdogdev/docs#114.
Helm: pgdogdev/helm#140.
Fixes #1521.

@jkaczman
jkaczman requested a review from levkk September 14, 2026 15:03
Comment thread integration/rust/tests/integration/omni_timestamps.rs
Comment thread integration/pgdog.toml Outdated
Comment thread pgdog/src/backend/replication/logical/subscriber/context.rs Outdated
Comment thread pgdog/src/backend/prepared_statements.rs
Comment thread pgdog/src/frontend/client/query_engine/rewrite.rs Outdated
Comment thread pgdog/src/frontend/client/mod.rs
Comment thread pgdog/src/frontend/client/transaction_type.rs
Comment thread pgdog/src/frontend/prepared_statements/global_cache.rs Outdated
Comment thread pgdog/src/frontend/prepared_statements/global_cache.rs
Comment thread pgdog/src/frontend/router/parser/cache/ast.rs Outdated
Comment thread pgdog/src/frontend/router/parser/cache/context.rs
Comment thread pgdog/src/frontend/router/parser/rewrite/statement/auto_id.rs Outdated
Comment thread pgdog/src/frontend/router/parser/rewrite/statement/mod.rs Outdated
Comment thread pgdog/src/frontend/router/parser/rewrite/statement/plan.rs
Comment thread pgdog/src/frontend/router/parser/rewrite/statement/plan.rs Outdated
Comment thread pgdog/src/frontend/router/parser/rewrite/statement/timestamp.rs

@levkk levkk left a comment

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.

Image

@jkaczman jkaczman changed the title [Early Draft] feat: re-write date/time functions (calls + schema) in omni inserts feat: re-write date/time functions (calls + DEFAULT) in omni inserts Sep 15, 2026
@jkaczman
jkaczman marked this pull request as ready for review September 15, 2026 23:17
@jkaczman
jkaczman merged commit b7979cf into main Sep 16, 2026
30 checks passed
@jkaczman
jkaczman deleted the jk-use-proxy-time branch September 16, 2026 00:01
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.

[Rewrites] Omnisharded inserts with timestamps should use proxy time

2 participants