diff --git a/src/sqlparser/src/parser.rs b/src/sqlparser/src/parser.rs index 7e8bf9c1042a..84dc34ada3b6 100644 --- a/src/sqlparser/src/parser.rs +++ b/src/sqlparser/src/parser.rs @@ -549,7 +549,7 @@ impl Parser { })); let token = self.next_token(); - let expr = match token.token { + let expr = match token.token.clone() { Token::Word(w) => match w.keyword { Keyword::TRUE | Keyword::FALSE | Keyword::NULL => { self.prev_token(); @@ -593,7 +593,7 @@ impl Parser { }) } k if keywords::RESERVED_FOR_COLUMN_OR_TABLE_NAME.contains(&k) => { - parser_err!(format!("syntax error at or near \"{w}\"")) + parser_err!(format!("syntax error at or near {token}")) } // Here `w` is a word, check if it's a part of a multi-part // identifier, a function call, or a simple identifier: @@ -1232,7 +1232,7 @@ impl Parser { // for keyword 'array' self.prev_token(); } - parser_err!(format!("syntax error at or near '{}'", self.peek_token()))? + parser_err!(format!("syntax error at or near {}", self.peek_token()))? } else { Ok(()) } @@ -3435,10 +3435,10 @@ impl Parser { /// Parse a simple one-word identifier (possibly quoted, possibly a non-reserved keyword) pub fn parse_identifier_non_reserved(&mut self) -> Result { let token = self.next_token(); - match token.token { + match token.token.clone() { Token::Word(w) => { match keywords::RESERVED_FOR_COLUMN_OR_TABLE_NAME.contains(&w.keyword) { - true => parser_err!(format!("syntax error at or near \"{w}\"")), + true => parser_err!(format!("syntax error at or near {token}")), false => Ok(w.to_ident()?), } } diff --git a/src/sqlparser/tests/sqlparser_common.rs b/src/sqlparser/tests/sqlparser_common.rs index ce3ec095ce28..0fc2f3c2530f 100644 --- a/src/sqlparser/tests/sqlparser_common.rs +++ b/src/sqlparser/tests/sqlparser_common.rs @@ -253,7 +253,8 @@ fn parse_select_all() { #[test] fn parse_select_all_distinct() { let result = parse_sql_statements("SELECT ALL DISTINCT name FROM customer"); - assert!(format!("{}", result.unwrap_err()).contains("syntax error at or near \"DISTINCT\"")); + assert!(format!("{}", result.unwrap_err()) + .contains("syntax error at or near DISTINCT at line:1, column:20")); } #[test] diff --git a/src/sqlparser/tests/sqlparser_postgres.rs b/src/sqlparser/tests/sqlparser_postgres.rs index 4e45f93a8c8a..d94f1b06b166 100644 --- a/src/sqlparser/tests/sqlparser_postgres.rs +++ b/src/sqlparser/tests/sqlparser_postgres.rs @@ -1047,7 +1047,7 @@ fn parse_array() { assert_eq!( parse_sql_statements(sql), Err(ParserError::ParserError( - "syntax error at or near '[ at line:1, column:28'".to_string() + "syntax error at or near [ at line:1, column:28".to_string() )) ); @@ -1055,7 +1055,7 @@ fn parse_array() { assert_eq!( parse_sql_statements(sql), Err(ParserError::ParserError( - "syntax error at or near '[ at line:1, column:24'".to_string() + "syntax error at or near [ at line:1, column:24".to_string() )) ); @@ -1063,7 +1063,7 @@ fn parse_array() { assert_eq!( parse_sql_statements(sql), Err(ParserError::ParserError( - "syntax error at or near 'ARRAY at line:1, column:27'".to_string() + "syntax error at or near ARRAY at line:1, column:27".to_string() )) ); @@ -1071,7 +1071,7 @@ fn parse_array() { assert_eq!( parse_sql_statements(sql), Err(ParserError::ParserError( - "syntax error at or near 'ARRAY at line:1, column:23'".to_string() + "syntax error at or near ARRAY at line:1, column:23".to_string() )) ); diff --git a/src/sqlparser/tests/testdata/create.yaml b/src/sqlparser/tests/testdata/create.yaml index ab5822fc2bc0..92bdabc83048 100644 --- a/src/sqlparser/tests/testdata/create.yaml +++ b/src/sqlparser/tests/testdata/create.yaml @@ -35,7 +35,7 @@ - input: CREATE TABLE T (a STRUCT) formatted_sql: CREATE TABLE T (a STRUCT) - input: CREATE TABLE T (FULL INT) - error_msg: 'sql parser error: syntax error at or near "FULL"' + error_msg: 'sql parser error: syntax error at or near FULL at line:1, column:21' - input: CREATE TABLE T ("FULL" INT) formatted_sql: CREATE TABLE T ("FULL" INT) - input: CREATE USER user WITH SUPERUSER CREATEDB PASSWORD 'password' diff --git a/src/sqlparser/tests/testdata/select.yaml b/src/sqlparser/tests/testdata/select.yaml index b98b9b6ff4fb..bbbb5a72bbda 100644 --- a/src/sqlparser/tests/testdata/select.yaml +++ b/src/sqlparser/tests/testdata/select.yaml @@ -71,9 +71,9 @@ sql parser error: Expected ), found: minutes at line:1, column:62 Near "(t, x, interval '10'" - input: SELECT 1, FROM t - error_msg: 'sql parser error: syntax error at or near "FROM"' + error_msg: 'sql parser error: syntax error at or near FROM at line:1, column:15' - input: SELECT 1, WHERE true - error_msg: 'sql parser error: syntax error at or near "WHERE"' + error_msg: 'sql parser error: syntax error at or near WHERE at line:1, column:16' - input: SELECT timestamp with time zone '2022-10-01 12:00:00Z' AT TIME ZONE 'US/Pacific' formatted_sql: SELECT TIMESTAMP WITH TIME ZONE '2022-10-01 12:00:00Z' AT TIME ZONE 'US/Pacific' formatted_ast: 'Query(Query { with: None, body: Select(Select { distinct: All, projection: [UnnamedExpr(AtTimeZone { timestamp: TypedString { data_type: Timestamp(true), value: "2022-10-01 12:00:00Z" }, time_zone: "US/Pacific" })], from: [], lateral_views: [], selection: None, group_by: [], having: None }), order_by: [], limit: None, offset: None, fetch: None })'