Skip to content

https://github.com/pgdogdev/pgdog/pull/1541 - #140

Merged
jkaczman merged 4 commits into
mainfrom
jk-omni-writes-time-funcs
Sep 17, 2026
Merged

jkaczman merged 4 commits into
mainfrom
jk-omni-writes-time-funcs

Conversation

@jkaczman

Copy link
Copy Markdown
Contributor

No description provided.

jkaczman added a commit to pgdogdev/pgdog that referenced this pull request Sep 16, 2026
…1541)

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](https://www.postgresql.org/docs/current/functions-datetime.html)),
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.

@levkk levkk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!! Ty! If you could also bump Chart.yaml, I'll be able to release it as well!

@levkk levkk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀

@jkaczman
jkaczman merged commit ac792a7 into main Sep 17, 2026
2 checks passed
@jkaczman
jkaczman deleted the jk-omni-writes-time-funcs branch September 17, 2026 10:11
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