Skip to content

Commit

Permalink
fix(sqlparser): keyword after char shall not be consumed on error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangjinwu authored Oct 16, 2024
1 parent a2b6f4f commit b089d1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/sqlparser/src/parser_v2/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ fn keyword_datatype<S: TokenStream>(input: &mut StatefulStream<S>) -> PResult<Da
Keyword::INT | Keyword::INTEGER => empty.value(DataType::Int),
Keyword::BIGINT => empty.value(DataType::BigInt),
Keyword::STRING | Keyword::VARCHAR => empty.value(DataType::Varchar),
Keyword::CHAR | Keyword::CHARACTER => dispatch! {keyword;
Keyword::VARYING => empty.value(DataType::Varchar),
_ => opt(precision_in_range(..)).map(DataType::Char),
},
Keyword::CHAR | Keyword::CHARACTER => alt((
Keyword::VARYING.value(DataType::Varchar),
opt(precision_in_range(..)).map(DataType::Char),
)),
Keyword::UUID => empty.value(DataType::Uuid),
Keyword::DATE => empty.value(DataType::Date),
Keyword::TIMESTAMP => with_time_zone().map(DataType::Timestamp),
Expand Down
5 changes: 5 additions & 0 deletions src/sqlparser/tests/testdata/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
formatted_ast: 'CreateSchema { schema_name: ObjectName([Ident { value: "t", quote_style: None }]), if_not_exists: true, user_specified: None }'
- input: CREATE OR REPLACE TABLE t (a INT)
formatted_sql: CREATE OR REPLACE TABLE t (a INT)
- input: CREATE OR REPLACE TABLE t (a CHAR AS)
error_msg: |-
sql parser error: expected an expression, found: )
LINE 1: CREATE OR REPLACE TABLE t (a CHAR AS)
^
- input: CREATE TABLE t (a INT, b INT) AS SELECT 1 AS b, 2 AS a
formatted_sql: CREATE TABLE t (a INT, b INT) AS SELECT 1 AS b, 2 AS a
- input: CREATE SOURCE src
Expand Down

0 comments on commit b089d1e

Please sign in to comment.