Skip to content

bug: Filling structure with Decimal fields #1785

Open
@gelycot

Description

@gelycot

Bug Report

YDB GO SDK version:
v3.108.0

Environment
macOS Venture 13.4 pro M2

Current behavior:

When I try to scan a YDB column of type Decimal(22,9) into a struct field of type types.Decimal using ScanStruct, I get a cast error:

scan error on struct field name 'amount': cast failed 'Decimal(22,9)(&{value:[0 0 0 0 0 0 0 0 1 182 155 75 172 208 95 21] innerType:0x140002b8800})' to '*decimal.Decimal' destination at github.com/ydb-platform/ydb-go-sdk/v3/internal/value.(*decimalValue).castTo(value.go:640)atgithub.com/ydb-platform/ydb-go-sdk/v3/internal/value.(*optionalValue).castTo(value.go:1761)atgithub.com/ydb-platform/ydb-go-sdk/v3/internal/query/scanner.StructScanner.ScanStruct(struct.go:68)atgithub.com/ydb-platform/ydb-go-sdk/v3/internal/query.Row.ScanStruct(row.go:63)atmain.readTableDataWithDecimal(main.go:144)
`

Expected behavior:

I expect the Go SDK to support scanning Decimal columns into struct fields of type types.Decimal, similarly to how primitive types are mapped. The ScanStruct call should fill all fields without errors.

Steps to reproduce:

Create a table with a column of type Decimal(22,9) in YDB.
Define a Go struct with a field of type types.Decimal.
Select a row from the table using the Query Service and try to scan it into the struct using ScanStruct.
Observe a cast error for the decimal field.

Related code:

type RowData struct {
 ID     uint64 `sql:"id"`
 Amount types.Decimal `sql:"amount"`
}

var info RowData
if err := row.ScanStruct(&info); err != nil {
 return nil, fmt.Errorf("ошибка при сканировании строки: %w", err)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions