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

support "set time zone to 'some-timezone'" #617

Merged
merged 3 commits into from Sep 20, 2022

Conversation

waitingkuo
Copy link
Contributor

close #303

sqlparser-rs original only supports SET TIMEZONE = 'some-timezone' now.
there're many dbs support both TIMEZONE and TIME ZONE in the SET statement (e.g. postgresql, pyspark, ...)

this pr is to enable SET TIMEZONE = 'some-timezone'

src/parser.rs Outdated
Comment on lines 3777 to 3782
let variable = if self.parse_keywords(&vec![Keyword::TIME, Keyword::ZONE]) {
ObjectName(vec!["TIMEZONE".into()])
} else {
self.parse_object_name()?
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before parse_object_name, try to parse 'TIME ZONE' to see whether it works

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it works, combine TIME and ZONE to TIMEZONE

tests/sqlparser_common.rs Outdated Show resolved Hide resolved
Comment on lines +4686 to +4707
#[test]
fn parse_set_time_zone() {
match verified_stmt("SET TIMEZONE = 'UTC'") {
Statement::SetVariable {
local,
hivevar,
variable,
value,
} => {
assert!(!local);
assert!(!hivevar);
assert_eq!(variable, ObjectName(vec!["TIMEZONE".into()]));
assert_eq!(
value,
vec![Expr::Value(Value::SingleQuotedString("UTC".into()))]
);
}
_ => unreachable!(),
}

one_statement_parses_to("SET TIME ZONE TO 'UTC'", "SET TIMEZONE = 'UTC'");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test case for both TIME ZONE and TIMEZONE

@coveralls
Copy link

Pull Request Test Coverage Report for Build 3084544815

  • 25 of 25 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 85.589%

Totals Coverage Status
Change from base Build 3019512499: 0.03%
Covered Lines: 9752
Relevant Lines: 11394

💛 - Coveralls

@waitingkuo
Copy link
Contributor Author

@avantgardnerio @alamb this could enable set timezone and set time zone

Copy link

@avantgardnerio avantgardnerio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know this crate very well, but I like what you're doing :)

Copy link
Collaborator

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- thanks @waitingkuo

@alamb alamb merged commit fccae77 into sqlparser-rs:main Sep 20, 2022
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 this pull request may close these issues.

can not parse "SET TIME ZONE 'UTC'"
4 participants