Skip to content
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

Query parse error #3149

Closed
rnavarro opened this issue Sep 7, 2017 · 3 comments
Closed

Query parse error #3149

rnavarro opened this issue Sep 7, 2017 · 3 comments

Comments

@rnavarro
Copy link
Contributor

rnavarro commented Sep 7, 2017

I think this is a regression.

I have a query like this:

SELECT af.<col_3>, DATE_FORMAT(MAX(af.<col_1>), '%Y;%m;%e;23;59;59') fiscalEndDate, DATE_FORMAT(DATE_ADD(MAX(af.<col_1>), INTERVAL 1 YEAR), '%Y;%m;%e;23;59;59') fiscalAddDate, MAX(af.<col_1>) fiscalEndDateForSort FROM

af WHERE af.<col_2> = '1' AND af.<col_3> IN (123) GROUP BY af.<col_3>;

MySQL returns this error:

select af.<col_3>, DATE_FORMAT(MAX(af.<col_1>), '%Y;%m;%e;23;59;59') as fiscalEndDate, DATE_FORMAT(DATE_ADD(MAX(af.<col_1>), interval 1 year`), '%Y;%m;%e;23;59;59') as fiscalAddDate,
MAX(af.<col_1>) as fiscalEndDateForSort
from

as af where af. = '1' and af. in (123) group by af. limit 10001;`

The issue is here:
INTERVAL 1 YEAR) --> interval 1 `year`)

I think this issue is happening at the vttablet level?

@demmer
Copy link
Member

demmer commented Sep 7, 2017

This could be caused by the recent changes to support the create table DDLs since YEAR is now a keyword.

@bbeaudreault
Copy link
Contributor

I think we need to change IntervalExpr's Unit field to not be a ColIdent. @demmer is correct, that adding YEAR as a keyword caused it to become quoted due to https://github.com/youtube/vitess/blob/master/go/vt/sqlparser/ast.go#L2783. Not sure if there's a reason to make Unit a ColIdent

@bbeaudreault
Copy link
Contributor

bbeaudreault commented Sep 7, 2017

Yea, colident seems unnecessary. Here's the docs on that UNIT field: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-add

I think we should just change the Unit to a string

@sougou sougou mentioned this issue Nov 13, 2017
sougou added a commit to sougou/vitess that referenced this issue Nov 14, 2017
Issue vitessio#3149
In interval expressions keywords like year should printed
without escaping.
@sougou sougou closed this as completed Nov 14, 2017
frouioui added a commit to planetscale/vitess that referenced this issue Mar 26, 2024
…) (vitessio#3149)

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com>
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

No branches or pull requests

4 participants