Skip to content

min and max treated as keywords instead of functions #232

@ghost

Description

I've come across tables that have columns named 'min' and 'max',
I've also never seen max used as a keyword, only as a function.

consider the following example:

SELECT min, max FROM foo
;

Token.Keyword.DML                       :SELECT
Token.Keyword                           :  min
Token.Keyword                           :  max
Token.Keyword                           :FROM
Token.Name                              :  foo

In this case, min and max are not keywords, or atleast this query works in mysql to mean literal column names.

When min and max are used as functions they behave as expected, although the ttype 'Keyword' still seems inaccurate.

SELECT min(bar), max(baz) FROM foo
;

Token.Keyword.DML                       :SELECT
Token.Keyword                           :min
Token.Name                              :    bar
Token.Keyword                           :max
Token.Name                              :    baz
Token.Keyword                           :FROM
Token.Name                              :  foo

Of course this can be avoided by explicitly backticking columns names:

SELECT `min`, `max` FROM foo
;

Token.Keyword.DML                       :SELECT
Token.Name                              :    `min`
Token.Name                              :    `max`
Token.Keyword                           :FROM
Token.Name                              :  foo

But I can't expect the quires I deal with to be well-escaped so long as they run as expected on mysql.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions