@@ -174,10 +174,13 @@ func GetAssignmentCast(fromType *pgtypes.DoltgresType, toType *pgtypes.DoltgresT
174174 }
175175 // We check for the identity after checking the maps, as the identity may be overridden (such as for types that have
176176 // parameters). If the "to" type is a string type, then we do not use the identity, and use the I/O conversion below.
177- if fromType .ID == toType .ID && fromType .TypCategory != pgtypes .TypeCategory_StringTypes {
177+ if fromType .ID == toType .ID && fromType .TypCategory != pgtypes .TypeCategory_StringTypes && fromType . TypCategory != pgtypes . TypeCategory_BitStringTypes {
178178 return IdentityCast
179179 }
180+
180181 // All types have a built-in assignment cast to string types: https://www.postgresql.org/docs/15/sql-createcast.html
182+ // This is also where length checks occur for types like char(n), varchar(n), bit(n), etc., which is not great
183+ // TODO: move length checks to their own analyzer step
181184 if toType .TypCategory == pgtypes .TypeCategory_StringTypes {
182185 return func (ctx * sql.Context , val any , targetType * pgtypes.DoltgresType ) (any , error ) {
183186 if val == nil {
@@ -189,6 +192,17 @@ func GetAssignmentCast(fromType *pgtypes.DoltgresType, toType *pgtypes.DoltgresT
189192 }
190193 return targetType .IoInput (ctx , str )
191194 }
195+ } else if toType .TypCategory == pgtypes .TypeCategory_BitStringTypes {
196+ return func (ctx * sql.Context , val any , targetType * pgtypes.DoltgresType ) (any , error ) {
197+ if val == nil {
198+ return nil , nil
199+ }
200+ str , err := fromType .IoOutput (ctx , val )
201+ if err != nil {
202+ return nil , err
203+ }
204+ return targetType .IoInput (ctx , str )
205+ }
192206 }
193207 return nil
194208}
@@ -209,8 +223,8 @@ func GetImplicitCast(fromType *pgtypes.DoltgresType, toType *pgtypes.DoltgresTyp
209223
210224// addTypeCast registers the given type cast.
211225func addTypeCast (mutex * sync.RWMutex ,
212- castMap map [id.Type ]map [id.Type ]pgtypes.TypeCastFunction ,
213- castArray map [id.Type ][]* pgtypes.DoltgresType , cast TypeCast ) error {
226+ castMap map [id.Type ]map [id.Type ]pgtypes.TypeCastFunction ,
227+ castArray map [id.Type ][]* pgtypes.DoltgresType , cast TypeCast ) error {
214228 mutex .Lock ()
215229 defer mutex .Unlock ()
216230
@@ -240,8 +254,8 @@ func getPotentialCasts(mutex *sync.RWMutex, castArray map[id.Type][]*pgtypes.Dol
240254// getCast returns the type cast function that will cast the "from" type to the "to" type. Returns nil if such a cast is
241255// not valid.
242256func getCast (mutex * sync.RWMutex ,
243- castMap map [id.Type ]map [id.Type ]pgtypes.TypeCastFunction ,
244- fromType * pgtypes.DoltgresType , toType * pgtypes.DoltgresType , outerFunc getCastFunction ) pgtypes.TypeCastFunction {
257+ castMap map [id.Type ]map [id.Type ]pgtypes.TypeCastFunction ,
258+ fromType * pgtypes.DoltgresType , toType * pgtypes.DoltgresType , outerFunc getCastFunction ) pgtypes.TypeCastFunction {
245259 mutex .RLock ()
246260 defer mutex .RUnlock ()
247261
0 commit comments