feat: Support expression in SET statement (#574)

Co-authored-by: Alex Vasilev <vaspiring@gmail.com>
This commit is contained in:
Dmitry Patsura 2022-08-18 20:29:55 +03:00 committed by GitHub
parent eb7f1b005e
commit 6d8aacd85b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 63 additions and 52 deletions

View file

@ -3751,22 +3751,12 @@ impl<'a> Parser<'a> {
} else if self.consume_token(&Token::Eq) || self.parse_keyword(Keyword::TO) {
let mut values = vec![];
loop {
let token = self.peek_token();
let value = match (self.parse_value(), token) {
(Ok(value), _) => SetVariableValue::Literal(value),
(Err(_), Token::Word(ident)) => SetVariableValue::Ident(ident.to_ident()),
(Err(_), Token::Minus) => {
let next_token = self.next_token();
match next_token {
Token::Word(ident) => SetVariableValue::Ident(Ident {
quote_style: ident.quote_style,
value: format!("-{}", ident.value),
}),
_ => self.expected("word", next_token)?,
}
}
(Err(_), unexpected) => self.expected("variable value", unexpected)?,
let value = if let Ok(expr) = self.parse_expr() {
expr
} else {
self.expected("variable value", self.peek_token())?
};
values.push(value);
if self.consume_token(&Token::Comma) {
continue;