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 @@ -104,6 +104,10 @@ pub enum DataType {
///
/// [SQL Standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#national-character-string-type
NationalCharacterVarying(Option<CharacterLength>),
/// National char type, e.g. NATIONAL CHAR(10), [SQL Standard].
///
/// [SQL Standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#national-character-string-type
NationalChar(Option<CharacterLength>),
/// Uuid type.
Uuid,
/// Large character object with optional length,
Expand Down Expand Up @@ -557,6 +561,7 @@ impl fmt::Display for DataType {
DataType::NationalCharacterVarying(size) => {
format_character_string_type(f, "NATIONAL CHARACTER VARYING", size)
}
DataType::NationalChar(size) => format_character_string_type(f, "NATIONAL CHAR", size),
DataType::Uuid => write!(f, "UUID"),
DataType::CharacterLargeObject(size) => {
format_type_with_optional_length(f, "CHARACTER LARGE OBJECT", size, false)
Expand Down
8 changes: 8 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13865,6 +13865,12 @@ impl<'a> Parser<'a> {
))
}
}
Keyword::NATIONAL if self.peek_keyword(Keyword::CHAR) => {
let _ = self.parse_keyword(Keyword::CHAR);
Ok(DataType::NationalChar(
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 @@ -23076,6 +23082,8 @@ mod tests {
"NATIONAL CHARACTER VARYING(20)",
DataType::NationalCharacterVarying(length)
);
test_parse_data_type!(dialect, "NATIONAL CHAR", DataType::NationalChar(None));
test_parse_data_type!(dialect, "NATIONAL CHAR(20)", DataType::NationalChar(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 @@ -23490,6 +23490,8 @@ fn parse_national_character_string_types() {
"NATIONAL CHARACTER(4)",
"NATIONAL CHARACTER VARYING",
"NATIONAL CHARACTER VARYING(4)",
"NATIONAL CHAR",
"NATIONAL CHAR(4)",
] {
dialects.verified_stmt(&format!("CREATE TABLE t (c {data_type})"));
dialects.verified_expr(&format!("CAST('ab' AS {data_type})"));
Expand Down
Loading