Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ define_keywords!(
JAR,
JOIN,
JSON,
JSONB,
JSONFILE,
JSON_TABLE,
JULIAN,
Expand Down
1 change: 1 addition & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5641,6 +5641,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),
Expand Down
11 changes: 11 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down