You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by if...@apache.org on 2025/02/08 06:24:34 UTC

(datafusion-sqlparser-rs) branch main updated: Parse Postgres VARBIT datatype (#1703)

This is an automated email from the ASF dual-hosted git repository.

iffyio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new cad49232 Parse Postgres VARBIT datatype (#1703)
cad49232 is described below

commit cad49232c1247ed942de985ac958212071946528
Author: Michael Victor Zink <mi...@readyset.io>
AuthorDate: Fri Feb 7 22:24:29 2025 -0800

    Parse Postgres VARBIT datatype (#1703)
---
 src/ast/data_type.rs        |  8 +++++++-
 src/keywords.rs             |  1 +
 src/parser/mod.rs           |  1 +
 tests/sqlparser_postgres.rs | 26 ++++++++++++++++++++++++++
 4 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs
index 1f2b6be9..4f1f21e0 100644
--- a/src/ast/data_type.rs
+++ b/src/ast/data_type.rs
@@ -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}[]"),
diff --git a/src/keywords.rs b/src/keywords.rs
index 0178bf55..a67f6bc7 100644
--- a/src/keywords.rs
+++ b/src/keywords.rs
@@ -925,6 +925,7 @@ define_keywords!(
     VALUES,
     VALUE_OF,
     VARBINARY,
+    VARBIT,
     VARCHAR,
     VARIABLES,
     VARYING,
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 30124bbc..de2dc660 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -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),
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs
index 62da0f57..d8d97b49 100644
--- a/tests/sqlparser_postgres.rs
+++ b/tests/sqlparser_postgres.rs
@@ -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!(),
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org