PostgreSQL: Support `NCHAR VARYING` (#2908)
diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs
index abd7b8d..164eb8d 100644
--- a/src/ast/data_type.rs
+++ b/src/ast/data_type.rs
@@ -116,6 +116,10 @@
     ///
     /// [SQL Standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#national-character-string-type
     Nchar(Option<CharacterLength>),
+    /// National char varying type, e.g. NCHAR VARYING(10), [SQL Standard].
+    ///
+    /// [SQL Standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#national-character-string-type
+    NcharVarying(Option<CharacterLength>),
     /// Uuid type.
     Uuid,
     /// Large character object with optional length,
@@ -574,6 +578,7 @@
                 format_character_string_type(f, "NATIONAL CHAR VARYING", size)
             }
             DataType::Nchar(size) => format_character_string_type(f, "NCHAR", size),
+            DataType::NcharVarying(size) => format_character_string_type(f, "NCHAR VARYING", size),
             DataType::Uuid => write!(f, "UUID"),
             DataType::CharacterLargeObject(size) => {
                 format_type_with_optional_length(f, "CHARACTER LARGE OBJECT", size, false)
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 6d89c62..76bd114 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -13877,7 +13877,15 @@
                         ))
                     }
                 }
-                Keyword::NCHAR => Ok(DataType::Nchar(self.parse_optional_character_length()?)),
+                Keyword::NCHAR => {
+                    if self.parse_keyword(Keyword::VARYING) {
+                        Ok(DataType::NcharVarying(
+                            self.parse_optional_character_length()?,
+                        ))
+                    } else {
+                        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()?)),
@@ -23100,6 +23108,7 @@
             );
             test_parse_data_type!(dialect, "NCHAR", DataType::Nchar(None));
             test_parse_data_type!(dialect, "NCHAR(20)", DataType::Nchar(length));
+            test_parse_data_type!(dialect, "NCHAR VARYING(20)", DataType::NcharVarying(length));
         }
 
         #[test]
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index f2c2d30..cf4f11c 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -23494,6 +23494,7 @@
         "NATIONAL CHAR VARYING(4)",
         "NCHAR",
         "NCHAR(4)",
+        "NCHAR VARYING(4)",
     ] {
         dialects.verified_stmt(&format!("CREATE TABLE t (c {data_type})"));
         dialects.verified_expr(&format!("CAST('ab' AS {data_type})"));