mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 19:27:21 +00:00
Add support for JSONB
datatype (#1089)
This commit is contained in:
parent
7cb1654d81
commit
5d66dc5dc9
4 changed files with 17 additions and 1 deletions
|
@ -196,8 +196,10 @@ pub enum DataType {
|
|||
Timestamp(Option<u64>, TimezoneInfo),
|
||||
/// Interval
|
||||
Interval,
|
||||
/// JSON type used in BigQuery
|
||||
/// JSON type
|
||||
JSON,
|
||||
/// Binary JSON type
|
||||
JSONB,
|
||||
/// Regclass used in postgresql serial
|
||||
Regclass,
|
||||
/// Text
|
||||
|
@ -340,6 +342,7 @@ impl fmt::Display for DataType {
|
|||
}
|
||||
DataType::Interval => write!(f, "INTERVAL"),
|
||||
DataType::JSON => write!(f, "JSON"),
|
||||
DataType::JSONB => write!(f, "JSONB"),
|
||||
DataType::Regclass => write!(f, "REGCLASS"),
|
||||
DataType::Text => write!(f, "TEXT"),
|
||||
DataType::String(size) => format_type_with_optional_length(f, "STRING", size, false),
|
||||
|
|
|
@ -366,6 +366,7 @@ define_keywords!(
|
|||
JAR,
|
||||
JOIN,
|
||||
JSON,
|
||||
JSONB,
|
||||
JSONFILE,
|
||||
JSON_TABLE,
|
||||
JULIAN,
|
||||
|
|
|
@ -5645,6 +5645,7 @@ impl<'a> Parser<'a> {
|
|||
// parse_interval for a taste.
|
||||
Keyword::INTERVAL => Ok(DataType::Interval),
|
||||
Keyword::JSON => Ok(DataType::JSON),
|
||||
Keyword::JSONB => Ok(DataType::JSONB),
|
||||
Keyword::REGCLASS => Ok(DataType::Regclass),
|
||||
Keyword::STRING => Ok(DataType::String(self.parse_optional_precision()?)),
|
||||
Keyword::TEXT => Ok(DataType::Text),
|
||||
|
|
|
@ -2172,6 +2172,17 @@ fn parse_cast() {
|
|||
},
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
|
||||
let sql = "SELECT CAST(details AS JSONB) FROM customer";
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
&Expr::Cast {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("details"))),
|
||||
data_type: DataType::JSONB,
|
||||
format: None,
|
||||
},
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue