mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Parse Postgres VARBIT datatype (#1703)
This commit is contained in:
parent
86abbd6028
commit
cad49232c1
4 changed files with 35 additions and 1 deletions
|
@ -328,10 +328,15 @@ pub enum DataType {
|
|||
/// [MySQL]: https://dev.mysql.com/doc/refman/9.1/en/bit-type.html
|
||||
/// [MSSQL]: https://learn.microsoft.com/en-us/sql/t-sql/data-types/bit-transact-sql?view=sql-server-ver16
|
||||
Bit(Option<u64>),
|
||||
/// Variable-length bit string e.g. [Postgres]
|
||||
/// `BIT VARYING(n)`: Variable-length bit string e.g. [Postgres]
|
||||
///
|
||||
/// [Postgres]: https://www.postgresql.org/docs/current/datatype-bit.html
|
||||
BitVarying(Option<u64>),
|
||||
/// `VARBIT(n)`: Variable-length bit string. [Postgres] alias for `BIT VARYING`
|
||||
///
|
||||
/// [Postgres]: https://www.postgresql.org/docs/current/datatype.html
|
||||
VarBit(Option<u64>),
|
||||
///
|
||||
/// Custom type such as enums
|
||||
Custom(ObjectName, Vec<String>),
|
||||
/// Arrays
|
||||
|
@ -550,6 +555,7 @@ impl fmt::Display for DataType {
|
|||
DataType::BitVarying(size) => {
|
||||
format_type_with_optional_length(f, "BIT VARYING", size, false)
|
||||
}
|
||||
DataType::VarBit(size) => format_type_with_optional_length(f, "VARBIT", size, false),
|
||||
DataType::Array(ty) => match ty {
|
||||
ArrayElemTypeDef::None => write!(f, "ARRAY"),
|
||||
ArrayElemTypeDef::SquareBracket(t, None) => write!(f, "{t}[]"),
|
||||
|
|
|
@ -925,6 +925,7 @@ define_keywords!(
|
|||
VALUES,
|
||||
VALUE_OF,
|
||||
VARBINARY,
|
||||
VARBIT,
|
||||
VARCHAR,
|
||||
VARIABLES,
|
||||
VARYING,
|
||||
|
|
|
@ -8779,6 +8779,7 @@ impl<'a> Parser<'a> {
|
|||
Ok(DataType::Bit(self.parse_optional_precision()?))
|
||||
}
|
||||
}
|
||||
Keyword::VARBIT => Ok(DataType::VarBit(self.parse_optional_precision()?)),
|
||||
Keyword::UUID => Ok(DataType::Uuid),
|
||||
Keyword::DATE => Ok(DataType::Date),
|
||||
Keyword::DATE32 => Ok(DataType::Date32),
|
||||
|
|
|
@ -5327,3 +5327,29 @@ fn parse_bitstring_literal() {
|
|||
))]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_varbit_datatype() {
|
||||
match pg_and_generic().verified_stmt("CREATE TABLE foo (x VARBIT, y VARBIT(42))") {
|
||||
Statement::CreateTable(CreateTable { columns, .. }) => {
|
||||
assert_eq!(
|
||||
columns,
|
||||
vec![
|
||||
ColumnDef {
|
||||
name: "x".into(),
|
||||
data_type: DataType::VarBit(None),
|
||||
collation: None,
|
||||
options: vec![],
|
||||
},
|
||||
ColumnDef {
|
||||
name: "y".into(),
|
||||
data_type: DataType::VarBit(Some(42)),
|
||||
collation: None,
|
||||
options: vec![],
|
||||
}
|
||||
]
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue