Skip to content

Postgres: Support INTERVAL data type options #1984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mvzink
Copy link
Contributor

@mvzink mvzink commented Jul 30, 2025

Postgres allows extra options for the INTERVAL data type; namely fields and subsecond precision. For example '3 years 1 second'::interval year to month casts the interval and strips the seconds, and '1.3333 seconds'::interval(1) returns 1.3 seconds.

This is supported by adding two optional fields to DataType::Interval, along with a new enum for the allowed fields.

Note that MSSQL also supports similar options, but with more complicated precision syntax, e.g. INTERVAL HOUR(p) TO SECOND(q). This is not implemented in this commit because I don't have a way to test it.

[Postgres] allows extra options for the `INTERVAL` data type; namely
fields and subsecond precision. For example `'3 years 1
second'::interval year to month` casts the interval and strips the
seconds, and `'1.3333 seconds'::interval(1)` returns `1.3` seconds.

This is supported by adding two optional fields to `DataType::Interval`,
along with a new `enum` for the allowed fields.

Note that [MSSQL] also supports similar options, but with more
complicated precision syntax, e.g. `INTERVAL HOUR(p) TO SECOND(q)`. This
is not implemented in this commit because I don't have a way to test it.

[Postgres]: https://www.postgresql.org/docs/17/datatype-datetime.html
[MSSQL]: https://learn.microsoft.com/en-us/sql/odbc/reference/appendixes/sql-data-types?view=sql-server-ver17
@mvzink mvzink force-pushed the push-mnyzxktlvzrp branch from c1096a8 to 54ef1f7 Compare July 31, 2025 15:23
Comment on lines +350 to +355
/// Optional [Postgres] field list and precision: `interval [ fields ] [ (p) ]`
///
/// [Postgres]: https://www.postgresql.org/docs/17/datatype-datetime.html
Interval {
fields: Option<IntervalFields>,
precision: Option<u64>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Optional [Postgres] field list and precision: `interval [ fields ] [ (p) ]`
///
/// [Postgres]: https://www.postgresql.org/docs/17/datatype-datetime.html
Interval {
fields: Option<IntervalFields>,
precision: Option<u64>,
Interval {
/// `Example syntax`
///
/// [Postgres]: https://www.postgresql.org/docs/17/datatype-datetime.html
fields: Option<IntervalFields>,
/// `Example syntax`
///
/// [Postgres]: https://www.postgresql.org/docs/17/datatype-datetime.html
precision: Option<u64>,

Could we move the documentation to the individual properties?

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