diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs index 96071c228..e0f36646a 100644 --- a/src/ast/data_type.rs +++ b/src/ast/data_type.rs @@ -32,7 +32,7 @@ pub enum DataType { /// Large character object e.g. CLOB(1000) Clob(u64), /// Fixed-length binary type e.g. BINARY(10) - Binary(u64), + Binary(Option), /// Variable-length binary type e.g. VARBINARY(10) Varbinary(u64), /// Large binary object e.g. BLOB(1000) @@ -75,6 +75,9 @@ pub enum DataType { Custom(ObjectName), /// Arrays Array(Box), + /// Bitfield + Bit(Option), + Json, } impl fmt::Display for DataType { @@ -86,7 +89,10 @@ impl fmt::Display for DataType { } DataType::Uuid => write!(f, "UUID"), DataType::Clob(size) => write!(f, "CLOB({})", size), - DataType::Binary(size) => write!(f, "BINARY({})", size), + DataType::Binary(size) => match size { + None => write!(f, "BINARY"), + Some(s) => write!(f, "BINARY({})", s) + }, DataType::Varbinary(size) => write!(f, "VARBINARY({})", size), DataType::Blob(size) => write!(f, "BLOB({})", size), DataType::Decimal(precision, scale) => { @@ -115,7 +121,12 @@ impl fmt::Display for DataType { DataType::String => write!(f, "STRING"), DataType::Bytea => write!(f, "BYTEA"), DataType::Array(ty) => write!(f, "{}[]", ty), + DataType::Bit(size) => match size { + None => write!(f, "BIT"), + Some(s) => write!(f, "BIT({})", s) + }, DataType::Custom(ty) => write!(f, "{}", ty), + DataType::Json => write!(f, "JSON"), } } } diff --git a/src/ast/operator.rs b/src/ast/operator.rs index 244ea517c..f1759b2e9 100644 --- a/src/ast/operator.rs +++ b/src/ast/operator.rs @@ -86,6 +86,8 @@ pub enum BinaryOperator { PGRegexIMatch, PGRegexNotMatch, PGRegexNotIMatch, + JsonColumnPath, + JsonInlinePath, } impl fmt::Display for BinaryOperator { @@ -121,6 +123,8 @@ impl fmt::Display for BinaryOperator { BinaryOperator::PGRegexIMatch => "~*", BinaryOperator::PGRegexNotMatch => "!~", BinaryOperator::PGRegexNotIMatch => "!~*", + BinaryOperator::JsonColumnPath => "->", + BinaryOperator::JsonInlinePath => "->>", }) } } diff --git a/src/keywords.rs b/src/keywords.rs index 8f73836c4..b64d42997 100644 --- a/src/keywords.rs +++ b/src/keywords.rs @@ -98,6 +98,7 @@ define_keywords!( BETWEEN, BIGINT, BINARY, + BIT, BLOB, BOOLEAN, BOTH, @@ -254,6 +255,7 @@ define_keywords!( IS, ISOLATION, JOIN, + JSON, JSONFILE, KEY, LAG, diff --git a/src/parser.rs b/src/parser.rs index 45b3bea0e..4864f324b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2090,6 +2090,12 @@ impl<'a> Parser<'a> { let (precision, scale) = self.parse_optional_precision_scale()?; Ok(DataType::Decimal(precision, scale)) } + Keyword::BINARY => Ok(DataType::Binary(self.parse_optional_precision()?)), + Keyword::VARBINARY => Ok(DataType::Varbinary(self.parse_required_precision()?)), + Keyword::CLOB => Ok(DataType::Clob(self.parse_required_precision()?)), + Keyword::BLOB => Ok(DataType::Blob(self.parse_required_precision()?)), + Keyword::BIT => Ok(DataType::Bit(self.parse_optional_precision()?)), + Keyword::JSON => Ok(DataType::Json), _ => { self.prev_token(); let type_name = self.parse_object_name()?; @@ -2218,6 +2224,18 @@ impl<'a> Parser<'a> { } } + pub fn parse_required_precision(&mut self) -> Result { + if self.consume_token(&Token::LParen) { + let n = self.parse_literal_uint()?; + self.expect_token(&Token::RParen)?; + Ok(n) + } else { + Err(ParserError::ParserError( + "expected precision data type".to_string(), + )) + } + } + pub fn parse_optional_precision_scale( &mut self, ) -> Result<(Option, Option), ParserError> {