Skip to content

can not parse "SET TIME ZONE 'UTC'"  #303

Closed

Description

@435201823

It was normal to parse "SET TIME ZONE 'UTC'" a few days ago. Today I tried to parse "SET TIME ZONE 'UTC'" and there was an error.

pub fn sql_parse_test() {
    use sqlparser::dialect::GenericDialect;
    use sqlparser::parser::Parser;

    let sql = r#"set time zone 'UTC'"#;

    let dialect = GenericDialect {};

    let ast = Parser::parse_sql(&dialect, sql).unwrap();

    println!("AST: {:?}", ast);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_sql_parse() {
        sql_parse_test();
    }
}

called `Result::unwrap()` on an `Err` value: ParserError("Expected equals sign or TO, found: zone")
thread 'func::sql_parse_test::tests::test_sql_parse' panicked at 'called `Result::unwrap()` on an `Err` value: ParserError("Expected equals sign or TO, found: zone")', src\func\sql_parse_test.rs:9:48

Activity

  1. waitingkuo commented on Sep 19, 2022

    @waitingkuo
    Contributor

    @435201823 which sqlparser version did you use that worked? i switched back to 0.5.0 but it still not works

  2. step-baby commented on Nov 25, 2022

    @step-baby
    Contributor

    The latest version of sqlparse still fails to parse SET TIME ZONE 'UTC'

  3. waitingkuo commented on Nov 25, 2022

    @waitingkuo
    Contributor

    @alamb i think we could reopen this and discuss.
    We only support SET TIME ZONE TO 'UTC' and SET TIME ZONE = 'UTC'
    but not SET TIME ZONE 'UTC'

    i'm not familiar with how other db works, in postgrseql, TIMEZONE is the only variable that support SET SOMETHING 'VALUE'
    https://www.postgresql.org/docs/current/sql-set.html

  4. reopened this on Nov 27, 2022
  5. alamb commented on Nov 27, 2022

    @alamb
    Contributor

    Reopened -- I think the typical strategy in these cases is to reflect the difference between SET TIME ZONE = 'UTC'
    and SET TIME ZONE 'UTC' in the ast and then downstream systems can figure out if they want to treat them equivalently or not

  6. waitingkuo commented on Nov 28, 2022

    @waitingkuo
    Contributor

    @alamb i updated the pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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