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

Error on some GRANTs when trailing commas are enabled #1211

Closed
MohamedAbdeen21 opened this issue Apr 11, 2024 · 0 comments · Fixed by #1318
Closed

Error on some GRANTs when trailing commas are enabled #1211

MohamedAbdeen21 opened this issue Apr 11, 2024 · 0 comments · Fixed by #1318

Comments

@MohamedAbdeen21
Copy link
Contributor

MohamedAbdeen21 commented Apr 11, 2024

How to reproduce

use sqlparser::{
    dialect::GenericDialect,
    parser::{Parser, ParserError, ParserOptions},
};

fn main() -> Result<(), ParserError> {
    let dialect = GenericDialect {};
    let options = ParserOptions::new().with_trailing_commas(true);

    let result = Parser::new(&dialect)
        .with_options(options)
        .try_with_sql("GRANT USAGE, SELECT ON SEQUENCE p TO u")?
        .parse_statements();

    println!("{:?}", result);

    Ok(())
}

Output

Err(ParserError("Expected ON, found: SELECT at Line: 1, Column 14"))

Expected Output

Should parse successfully.

Ok([Grant { privileges: Actions([Usage, Select { columns: None }]), objects: Sequenc
es([ObjectName([Ident { value: "p", quote_style: None }])]), grantees: [Ident { valu
e: "u", quote_style: None }], with_grant_option: false, granted_by: None }])

Cause

parse_comma_separated guesses that the comma is a trailing comma since it's followed by a reserved keyword (SELECT).

@MohamedAbdeen21 MohamedAbdeen21 changed the title Error on GRANT statements when trailing commas enabled Error on some GRANTs when trailing commas are enabled Apr 11, 2024
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

Successfully merging a pull request may close this issue.

1 participant