mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
fix: Supports updating valid column names whose names are the same as… (#725)
* fix: Supports updating valid column names whose names are the same as keywords * fix: warning
This commit is contained in:
parent
57083a0df1
commit
10652b61b4
1 changed files with 21 additions and 25 deletions
|
@ -3916,41 +3916,19 @@ impl<'a> Parser<'a> {
|
|||
Ok(ObjectName(idents))
|
||||
}
|
||||
|
||||
/// Parse identifiers strictly i.e. don't parse keywords
|
||||
pub fn parse_identifiers_non_keywords(&mut self) -> Result<Vec<Ident>, ParserError> {
|
||||
/// Parse identifiers
|
||||
pub fn parse_identifiers(&mut self) -> Result<Vec<Ident>, ParserError> {
|
||||
let mut idents = vec![];
|
||||
loop {
|
||||
match self.peek_token() {
|
||||
Token::Word(w) => {
|
||||
if w.keyword != Keyword::NoKeyword {
|
||||
break;
|
||||
}
|
||||
|
||||
idents.push(w.to_ident());
|
||||
}
|
||||
Token::EOF | Token::Eq => break,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
self.next_token();
|
||||
}
|
||||
|
||||
Ok(idents)
|
||||
}
|
||||
|
||||
/// Parse identifiers
|
||||
pub fn parse_identifiers(&mut self) -> Result<Vec<Ident>, ParserError> {
|
||||
let mut idents = vec![];
|
||||
loop {
|
||||
match self.next_token() {
|
||||
Token::Word(w) => {
|
||||
idents.push(w.to_ident());
|
||||
}
|
||||
Token::EOF => break,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(idents)
|
||||
}
|
||||
|
||||
|
@ -5312,7 +5290,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// Parse a `var = expr` assignment, used in an UPDATE statement
|
||||
pub fn parse_assignment(&mut self) -> Result<Assignment, ParserError> {
|
||||
let id = self.parse_identifiers_non_keywords()?;
|
||||
let id = self.parse_identifiers()?;
|
||||
self.expect_token(&Token::Eq)?;
|
||||
let value = self.parse_expr()?;
|
||||
Ok(Assignment { id, value })
|
||||
|
@ -6325,4 +6303,22 @@ mod tests {
|
|||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_update_has_keyword() {
|
||||
let sql = r#"UPDATE test SET name=$1,
|
||||
value=$2,
|
||||
where=$3,
|
||||
create=$4,
|
||||
is_default=$5,
|
||||
classification=$6,
|
||||
sort=$7
|
||||
WHERE id=$8"#;
|
||||
let pg_dialect = PostgreSqlDialect {};
|
||||
let ast = Parser::parse_sql(&pg_dialect, sql).unwrap();
|
||||
assert_eq!(
|
||||
ast[0].to_string(),
|
||||
r#"UPDATE test SET name = $1, value = $2, where = $3, create = $4, is_default = $5, classification = $6, sort = $7 WHERE id = $8"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue