sfaut opened a new issue, #2693:
URL: https://github.com/apache/datafusion-sqlparser-rs/issues/2693
MySQL and MariaDB accept compound time units in `EXTRACT` and in `INTERVAL`
expressions (`DATE_ADD`, `DATE_SUB`, `+ INTERVAL`...). `MySqlDialect` rejects
them, in 0.63.0 and on `main`:
~~~rust
use sqlparser::dialect::MySqlDialect;
use sqlparser::parser::Parser;
for sql in [
"SELECT EXTRACT(YEAR_MONTH FROM d) FROM t",
"SELECT DATE_ADD(d, INTERVAL '1-2' YEAR_MONTH) FROM t",
"SELECT d + INTERVAL '1 2' DAY_HOUR FROM t",
] {
println!("{:?}", Parser::parse_sql(&MySqlDialect {}, sql));
}
~~~
~~~
Err(ParserError("Expected: date/time field, found: YEAR_MONTH at Line: 1,
Column: 16"))
Err(ParserError("INTERVAL requires a unit after the literal value at Line:
1, Column: 35"))
Err(ParserError("INTERVAL requires a unit after the literal value at Line:
1, Column: 27"))
~~~
The simple units (`DAY`, `MONTH`, `QUARTER`...) parse fine.
The compound units are the same 11 in MySQL and MariaDB:
`SECOND_MICROSECOND`, `MINUTE_MICROSECOND`, `MINUTE_SECOND`,
`HOUR_MICROSECOND`, `HOUR_SECOND`, `HOUR_MINUTE`, `DAY_MICROSECOND`,
`DAY_SECOND`, `DAY_MINUTE`, `DAY_HOUR`, `YEAR_MONTH`.
- MySQL:
https://dev.mysql.com/doc/refman/8.4/en/expressions.html#temporal-intervals
- MariaDB:
https://mariadb.com/docs/server/reference/sql-functions/date-time-functions/date-and-time-units
Thx,
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]