go-mssqldb
go-mssqldb copied to clipboard
bulkcopy: mssql: type 6e not implemented
When I am trying to perform bulk insert in my project, I found an error like below.
error="bulkcopy: mssql: type 6e not implemented"
After debugging the issue I found that, there is no code in the package for managing the data type of money.
Please check the bulkcopy.go file line 456. The case for handling money type is commented there.
// case typeMoney, typeMoney4, typeMoneyN:
As my database table contains some fields of money type, so I got above error. Can you please suggest how to manage data if the database contains field of type money?
There is an open PR to fix this. It is waiting until I resolve how to make decimals work.
Out of curiosity, what Go type are you using to represent your Money type?
For now I am using float32 for Money type, also tried float64 previously.
For easier reference: https://github.com/denisenkom/go-mssqldb/blob/master/bulkcopy.go#L504
My five cents:
-
0x6e
istypeMoneyN
and is for sql typemoney
andsmallmoney
with 8 and 4 bytes length - the microsoft fork also suffers from not supporting money as db table column type for
insert bulk
. - the PR should be this one https://github.com/denisenkom/go-mssqldb/pull/430
On "Out of curiosity, what Go type are you using to represent your Money type?", I guess, sth similar to what is supported for decimal: ints, floats and string. The implementation for decimals converts parameters to the var dec decimal.Decimal
but it doesn't not support decimal.Decimal
itself b/c that's an internal type. IMHO it should be considered to make this type public to provide an option for pulling out the conversion into the client.
As far as I remember the reason for using money
was to enable precise 8byte calculations with four fixed decimal digits and a lot of valid digits before the decimal point for very large amounts of money. Float64 is quite nasty in comparison.