Skip to content

Why gorm case sql.RawBytes to string when scanIntoMap? #7189

@APshenkin

Description

@APshenkin

GORM Playground Link

Description

I find out that GORM cast byte arrays to strings, if ColumnTypeScanType returns sql.RawBytes.

gorm/scan.go

Line 44 in 0daaf17

} else if b, ok := mapValue[column].(sql.RawBytes); ok {

This behaviour was introduced in 2020 and actually it's not clear why it do so.

I thing it's logical that if db value is sql.RawBytes, then it should return []byte, not string, because you can have arbitrary byte array there that during scanning should not change to other type.

go-sqlite return sql.RawBytes as type for BLOB which is https://www.sqlite.org/datatype3.htmlThe value is a blob of data, stored exactly as it was input.

But together with GORM if dest is map[string]interface{} we get string instead

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions