Skip to content

Commit 5d66dc5

Browse files
Add support for JSONB datatype (#1089)
1 parent 7cb1654 commit 5d66dc5

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

src/ast/data_type.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ pub enum DataType {
196196
Timestamp(Option<u64>, TimezoneInfo),
197197
/// Interval
198198
Interval,
199-
/// JSON type used in BigQuery
199+
/// JSON type
200200
JSON,
201+
/// Binary JSON type
202+
JSONB,
201203
/// Regclass used in postgresql serial
202204
Regclass,
203205
/// Text
@@ -340,6 +342,7 @@ impl fmt::Display for DataType {
340342
}
341343
DataType::Interval => write!(f, "INTERVAL"),
342344
DataType::JSON => write!(f, "JSON"),
345+
DataType::JSONB => write!(f, "JSONB"),
343346
DataType::Regclass => write!(f, "REGCLASS"),
344347
DataType::Text => write!(f, "TEXT"),
345348
DataType::String(size) => format_type_with_optional_length(f, "STRING", size, false),

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ define_keywords!(
366366
JAR,
367367
JOIN,
368368
JSON,
369+
JSONB,
369370
JSONFILE,
370371
JSON_TABLE,
371372
JULIAN,

src/parser/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5645,6 +5645,7 @@ impl<'a> Parser<'a> {
56455645
// parse_interval for a taste.
56465646
Keyword::INTERVAL => Ok(DataType::Interval),
56475647
Keyword::JSON => Ok(DataType::JSON),
5648+
Keyword::JSONB => Ok(DataType::JSONB),
56485649
Keyword::REGCLASS => Ok(DataType::Regclass),
56495650
Keyword::STRING => Ok(DataType::String(self.parse_optional_precision()?)),
56505651
Keyword::TEXT => Ok(DataType::Text),

tests/sqlparser_common.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,17 @@ fn parse_cast() {
21722172
},
21732173
expr_from_projection(only(&select.projection))
21742174
);
2175+
2176+
let sql = "SELECT CAST(details AS JSONB) FROM customer";
2177+
let select = verified_only_select(sql);
2178+
assert_eq!(
2179+
&Expr::Cast {
2180+
expr: Box::new(Expr::Identifier(Ident::new("details"))),
2181+
data_type: DataType::JSONB,
2182+
format: None,
2183+
},
2184+
expr_from_projection(only(&select.projection))
2185+
);
21752186
}
21762187

21772188
#[test]

0 commit comments

Comments
 (0)