prestodb / presto-go-client

A Presto client for the Go programming language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for DECIMAL type

fiorix opened this issue · comments

While looking at this I learned that Presto returns decimal types as literal strings. Perhaps this is why #11 and #12 wanted to implement this as strings.

I believe the right thing to do is to support decimals as float64 and sql.NullFloat64.

github.com/lib/pq supports scanning decimals to string, float64, and their variants sql.NullString and sql.NullFloat64. Despite not being able to convert to int64 for obvious reasons, a CAST(NULL to DECIMAL(10,2)) can be scanned to sql.NullInt64.

I haven't tried github.com/go-sql-driver/mysql but I believe it should be consistent with pq.

That said, we should probably do the same here.

This is a simple fix. Added a suggestion in #11 (comment) which should provide the same behavior as pq.