You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "sfaut (via GitHub)" <gi...@apache.org> on 2026/10/20 08:46:28 UTC

[I] MySQL: compound time units (`YEAR_MONTH`, `DAY_HOUR`...) fail in `EXTRACT` and `INTERVAL` [datafusion-sqlparser-rs]

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: github-unsubscribe@datafusion.apache.org.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