I have query from Business Object report that run in MySQL database
CREATE TABLE `mytable` (`date_type_column` date DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `mytable`(`date_type_column`) VALUES ('2019-01-02');
INSERT INTO `mytable`(`date_type_column`) VALUES ('2020-01-02');
INSERT INTO `mytable`(`date_type_column`) VALUES ('2021-01-02');
INSERT INTO `mytable`(`date_type_column`) VALUES ('2022-01-02');
SELECT
*
FROM
`mytable`
WHERE
date_type_column >= {d '2021-01-01 00:00:00'};
the question is what does {d '2022-02-01 00:00:00'}
syntax actually mean in this statemen ? It may be not correct SQL syntax but the query works "as is" in MySQL workbench 8.0. MySQL 5.7.39.
CodePudding user response:
This is ODBC escape syntax. It's described in the Expressions documentation:
{identifier expr} is ODBC escape syntax and is accepted for ODBC compatibility. The value is expr. The
{
and}
curly braces in the syntax should be written literally; they are not metasyntax as used elsewhere in syntax descriptions.
SQL-Server uses the identifier to determine how to parse expr. d
is used to create DATE
literals. See the SQL-Server documentation Date, Time, and Timestamp Literals. But MySQL ignores the identifier.
I can't explain why the query doesn't work for 2022 dates, it should be no different from writing
WHERE
mytable.mydate_Type_column >= '2022-02-01 00:00:00'
without the curly braces.