pggen icon indicating copy to clipboard operation
pggen copied to clipboard

Encoder panics on composite type arrays containing pgtype.Numeric

Open kirk-anchor opened this issue 1 year ago • 1 comments

Using an array of a composite type with a numeric column and no --go-type override results in a panic

panic: encode []FeeConfig: cannot convert {1 -2 2 false none} to Numeric

This does not occur if your generated structs use a string with --go-type 'numeric=string'

However pgtype.Numeric has a bug in string conversion, I reported it upstream https://github.com/jackc/pgtype/issues/210

For now, I will use the last pggen commit that still contains QuerierConfig and everything works properly with --go-type 'numeric=github.com/shopspring/decimal.Decimal'

kirk-anchor avatar Jan 04 '24 14:01 kirk-anchor

The string conversion bug has now been fixed in pgtype.Numeric so --go-type 'numeric=string' can be used as a workaround to allow using numeric columns in composite types

kirk-anchor avatar Jan 16 '24 10:01 kirk-anchor