Skip to content

Optional GROUP BY statement #2056

@Kimishu

Description

@Kimishu

Working on my custom sql validation, I needed somehow to check, does user provide group_by/limit+offset/sort_by clauses.
I got smth like this and found .group_by field as non-optional. Is it right?

let wrong_query = "SELECT * FROM example_table GROUP BY example_field";
//Parser returns success(!) below
if let Statement::Query(q) = Parser::parse_sql(&GenericDialect {}, &query)?.first().unwrap() {
     if q.limit_clause.is_none() {...}
     if q.order_by.is_none() {...}
     let select_query = query.body.as_select().unwrap();
     //And I expected smth like this:
     if select_query.group_by.is_none() {...}
}

Maybe I'm doing smth wrong and there is a proper and faster way for that?
Also I noticed a parse_optional_group_by fn but I didn't get how to use it., there is no info nor examples in docs about it. Looks like it's inner fn?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions