Skip to content
Open
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: 5 additions & 0 deletions src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ pub enum DataType {
///
/// [SQL Standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#national-character-string-type
NationalCharVarying(Option<CharacterLength>),
/// National char type, e.g. NCHAR(10), [SQL Standard].
///
/// [SQL Standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#national-character-string-type
Nchar(Option<CharacterLength>),
/// Uuid type.
Uuid,
/// Large character object with optional length,
Expand Down Expand Up @@ -569,6 +573,7 @@ impl fmt::Display for DataType {
DataType::NationalCharVarying(size) => {
format_character_string_type(f, "NATIONAL CHAR VARYING", size)
}
DataType::Nchar(size) => format_character_string_type(f, "NCHAR", size),
DataType::Uuid => write!(f, "UUID"),
DataType::CharacterLargeObject(size) => {
format_type_with_optional_length(f, "CHARACTER LARGE OBJECT", size, false)
Expand Down
3 changes: 3 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13877,6 +13877,7 @@ impl<'a> Parser<'a> {
))
}
}
Keyword::NCHAR => Ok(DataType::Nchar(self.parse_optional_character_length()?)),
Keyword::CLOB => Ok(DataType::Clob(self.parse_optional_precision()?)),
Keyword::BINARY => Ok(DataType::Binary(self.parse_optional_precision()?)),
Keyword::VARBINARY => Ok(DataType::Varbinary(self.parse_optional_binary_length()?)),
Expand Down Expand Up @@ -23095,6 +23096,8 @@ mod tests {
"NATIONAL CHAR VARYING(20)",
DataType::NationalCharVarying(length)
);
test_parse_data_type!(dialect, "NCHAR", DataType::Nchar(None));
test_parse_data_type!(dialect, "NCHAR(20)", DataType::Nchar(length));
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23493,6 +23493,8 @@ fn parse_national_character_string_types() {
"NATIONAL CHAR",
"NATIONAL CHAR(4)",
"NATIONAL CHAR VARYING(4)",
"NCHAR",
"NCHAR(4)",
] {
dialects.verified_stmt(&format!("CREATE TABLE t (c {data_type})"));
dialects.verified_expr(&format!("CAST('ab' AS {data_type})"));
Expand Down
Loading