@@ -85,7 +85,7 @@ pub enum DataType {
8585 ///
8686 /// [standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#binary-string-type
8787 /// [MS SQL Server]: https://learn.microsoft.com/pt-br/sql/t-sql/data-types/binary-and-varbinary-transact-sql?view=sql-server-ver16
88- Varbinary ( Option < u64 > ) ,
88+ Varbinary ( Option < BinaryLength > ) ,
8989 /// Large binary object with optional length e.g. BLOB, BLOB(1000), [standard], [Oracle]
9090 ///
9191 /// [standard]: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#binary-large-object-string-type
@@ -408,9 +408,7 @@ impl fmt::Display for DataType {
408408 }
409409 DataType :: Clob ( size) => format_type_with_optional_length ( f, "CLOB" , size, false ) ,
410410 DataType :: Binary ( size) => format_type_with_optional_length ( f, "BINARY" , size, false ) ,
411- DataType :: Varbinary ( size) => {
412- format_type_with_optional_length ( f, "VARBINARY" , size, false )
413- }
411+ DataType :: Varbinary ( size) => format_varbinary_type ( f, "VARBINARY" , size) ,
414412 DataType :: Blob ( size) => format_type_with_optional_length ( f, "BLOB" , size, false ) ,
415413 DataType :: TinyBlob => write ! ( f, "TINYBLOB" ) ,
416414 DataType :: MediumBlob => write ! ( f, "MEDIUMBLOB" ) ,
@@ -673,6 +671,18 @@ fn format_character_string_type(
673671 Ok ( ( ) )
674672}
675673
674+ fn format_varbinary_type (
675+ f : & mut fmt:: Formatter ,
676+ sql_type : & str ,
677+ size : & Option < BinaryLength > ,
678+ ) -> fmt:: Result {
679+ write ! ( f, "{sql_type}" ) ?;
680+ if let Some ( size) = size {
681+ write ! ( f, "({size})" ) ?;
682+ }
683+ Ok ( ( ) )
684+ }
685+
676686fn format_datetime_precision_and_tz (
677687 f : & mut fmt:: Formatter ,
678688 sql_type : & ' static str ,
@@ -862,6 +872,32 @@ impl fmt::Display for CharLengthUnits {
862872 }
863873}
864874
875+ #[ derive( Debug , Copy , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
876+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
877+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
878+ pub enum BinaryLength {
879+ IntegerLength {
880+ /// Default (if VARYING)
881+ length : u64 ,
882+ } ,
883+ /// VARBINARY(MAX) used in T-SQL (Microsoft SQL Server)
884+ Max ,
885+ }
886+
887+ impl fmt:: Display for BinaryLength {
888+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
889+ match self {
890+ BinaryLength :: IntegerLength { length } => {
891+ write ! ( f, "{}" , length) ?;
892+ }
893+ BinaryLength :: Max => {
894+ write ! ( f, "MAX" ) ?;
895+ }
896+ }
897+ Ok ( ( ) )
898+ }
899+ }
900+
865901/// Represents the data type of the elements in an array (if any) as well as
866902/// the syntax used to declare the array.
867903///
0 commit comments