Recommended way of working with the DECIMAL type #353
-
I exploring DuckDB currently and was wondering what the best way to store and retrieve financial data is. To circumvent any rounding related errors I want to use the DECIMAL data type. I wasn't able to find a good example of how the DECIMAL type translate into the GO world and vise versa. I'm curious about the level of DX that can be archived with what go-duckdb offers. Can anyone provide me some pointers or a simple example? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @trading-peter, have a look at It is not yet possible to bind it to a statement ( func (s *Stmt) bindValue(val driver.NamedValue, n int) (C.duckdb_state, error) {
switch v := val.Value.(type) {
case bool:
return C.duckdb_bind_boolean(*s.stmt, C.idx_t(n+1), C.bool(v)), nil
// ...
case Decimal:
// FIXME: implement NamedValueChecker to support custom data types.
name := typeToStringMap[TYPE_DECIMAL]
return C.DuckDBError, addIndexToError(unsupportedTypeError(name), n+1) |
Beta Was this translation helpful? Give feedback.
Hi @trading-peter, have a look at
types_test.go
. There is a testfunc TestDecimal(t *testing.T)
, including scanning the decimal type. Inappender_test.go
, you can findfunc TestAppenderDecimal(t *testing.T)
, which shows how to (bulk) insert decimals with theAppender
. Hope this helps! ✌️It is not yet possible to bind it to a statement (
query("SELECT $1...", myDecimal
). I'll try to get that in after the next release.