Skip to content

UNCACHE fails to parse with a semicolon #1244

Closed
@tv42

Description

@tv42

parse_sql normally doesn't care whether a single statement is terminated by a semicolon or end of string, but when parsing UNCACHE it does.

This deviation seems like a bug.

Discovered on sqlparser v0.43.1, tested on v0.45.0:

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

fn main() {
    let dialect = GenericDialect {};

    // With other SQL, semicolon being there or not does not seem to matter:
    {
        let no_semicolon = Parser::parse_sql(&dialect, "select 1");
        assert!(no_semicolon.is_ok());
    }
    {
        let with_semicolon = Parser::parse_sql(&dialect, "select 1;");
        assert!(with_semicolon.is_ok());
    }

    // With the UNCACHE statement, it does seem to matter.
    // Parsing only works when the semicolon is omitted:
    {
        let no_semicolon = Parser::parse_sql(&dialect, "uncache table foo");
        println!("no semicolon: {no_semicolon:?}");
        assert!(no_semicolon.is_ok());
    }
    {
        // BUG
        let with_semicolon = Parser::parse_sql(&dialect, "uncache table foo;");
        println!("with semicolon: {with_semicolon:?}");
        assert_eq!(
            with_semicolon,
            Err(ParserError::ParserError(
                "Expected an `EOF`, found: ; at Line: 1, Column 18".to_string()
            ))
        );
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions