You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "mvzink (via GitHub)" <gi...@apache.org> on 2025/07/30 18:40:51 UTC
[PR] Postgres: Support `INTERVAL` data type options [datafusion-sqlparser-rs]
mvzink opened a new pull request, #1984:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1984
[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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Postgres: Support `INTERVAL` data type options [datafusion-sqlparser-rs]
Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio merged PR #1984:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1984
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Postgres: Support `INTERVAL` data type options [datafusion-sqlparser-rs]
Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio commented on code in PR #1984:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1984#discussion_r2244838398
##########
src/dialect/mod.rs:
##########
@@ -1136,6 +1136,13 @@ pub trait Dialect: Debug + Any {
fn supports_notnull_operator(&self) -> bool {
false
}
+
+ /// Returns true if the dialect supports the `INTERVAL` data type with [Postgres]-style options.
Review Comment:
Could we add an example expression here? Thinking it would clarify the behavior without having folks consult the pg docs if they don't want to dig deeper into the syntax
##########
src/ast/data_type.rs:
##########
@@ -346,7 +346,11 @@ pub enum DataType {
/// [1]: https://docs.databricks.com/aws/en/sql/language-manual/data-types/timestamp-ntz-type
TimestampNtz,
/// Interval type.
- Interval,
+ ///
+ /// Optional [Postgres] field list and precision: `interval [ fields ] [ (p) ]`
+ ///
+ /// [Postgres]: https://www.postgresql.org/docs/17/datatype-datetime.html
+ Interval(Option<IntervalFields>, Option<u64>),
Review Comment:
Could we use a struct variant to contain the fields? thinking that would be clearer API wise and easier to document in the cases like this one where we have multiple entries e.g.
```
Interval {
/// Postgres ...
fields: Option<IntervalFields>,
/// Postgres ...
precision: Option<u64>
}
```
##########
src/parser/mod.rs:
##########
@@ -10995,6 +11000,85 @@ impl<'a> Parser<'a> {
}
}
+ pub fn parse_optional_interval_fields(
Review Comment:
```suggestion
fn maybe_parse_optional_interval_fields(
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Postgres: Support `INTERVAL` data type options [datafusion-sqlparser-rs]
Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio commented on code in PR #1984:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1984#discussion_r2247618510
##########
src/ast/data_type.rs:
##########
@@ -346,7 +346,14 @@ pub enum DataType {
/// [1]: https://docs.databricks.com/aws/en/sql/language-manual/data-types/timestamp-ntz-type
TimestampNtz,
/// Interval type.
- Interval,
+ ///
+ /// 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>,
Review Comment:
```suggestion
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?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org