Skip to content

Commit d9cd0de

Browse files
committed
Parse Postgres VARBIT datatype
1 parent 447142c commit d9cd0de

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/ast/data_type.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,15 @@ pub enum DataType {
324324
/// [MySQL]: https://dev.mysql.com/doc/refman/9.1/en/bit-type.html
325325
/// [MSSQL]: https://learn.microsoft.com/en-us/sql/t-sql/data-types/bit-transact-sql?view=sql-server-ver16
326326
Bit(Option<u64>),
327-
/// Variable-length bit string e.g. [Postgres]
327+
/// `BIT VARYING(n)`: Variable-length bit string e.g. [Postgres]
328328
///
329329
/// [Postgres]: https://www.postgresql.org/docs/current/datatype-bit.html
330330
BitVarying(Option<u64>),
331+
/// `VARBIT(n)`: Variable-length bit string. [Postgres] alias for `BIT VARYING`
332+
///
333+
/// [Postgres]: https://www.postgresql.org/docs/current/datatype.html
334+
VarBit(Option<u64>),
335+
///
331336
/// Custom type such as enums
332337
Custom(ObjectName, Vec<String>),
333338
/// Arrays
@@ -546,6 +551,7 @@ impl fmt::Display for DataType {
546551
DataType::BitVarying(size) => {
547552
format_type_with_optional_length(f, "BIT VARYING", size, false)
548553
}
554+
DataType::VarBit(size) => format_type_with_optional_length(f, "VARBIT", size, false),
549555
DataType::Array(ty) => match ty {
550556
ArrayElemTypeDef::None => write!(f, "ARRAY"),
551557
ArrayElemTypeDef::SquareBracket(t, None) => write!(f, "{t}[]"),

src/keywords.rs

+1
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ define_keywords!(
922922
VALUES,
923923
VALUE_OF,
924924
VARBINARY,
925+
VARBIT,
925926
VARCHAR,
926927
VARIABLES,
927928
VARYING,

src/parser/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8720,6 +8720,7 @@ impl<'a> Parser<'a> {
87208720
Ok(DataType::Bit(self.parse_optional_precision()?))
87218721
}
87228722
}
8723+
Keyword::VARBIT => Ok(DataType::VarBit(self.parse_optional_precision()?)),
87238724
Keyword::UUID => Ok(DataType::Uuid),
87248725
Keyword::DATE => Ok(DataType::Date),
87258726
Keyword::DATE32 => Ok(DataType::Date32),

0 commit comments

Comments
 (0)