Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database/sql: not allowing values in range [2^64 -1 - 2^63] in sql library for uint64 #20238

Closed
sarathsp06 opened this issue May 4, 2017 · 5 comments

Comments

@sarathsp06
Copy link

@sarathsp06 sarathsp06 commented May 4, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/sarath/go"
GORACE=""
GOROOT="/home/sarath/goroot"
GOTOOLDIR="/home/sarath/goroot/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build602887406=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

Used database/sql lib to insert a a value ( 2^64 - 1 ) as uint64 to a mysql column of type decimal(20,0)

What did you expect to see?

Successful insertion

What did you see instead?

Insertion fails with the following error

"uint64 values with high bit set are not supported"

Code that generates the error

In drivers/types.go found the code

if u64 >= 1<<63 {
			return nil, fmt.Errorf("uint64 values with high bit set are not supported")
}

Here is the link for the code snippet

github/golang

@sarathsp06
Copy link
Author

@sarathsp06 sarathsp06 commented May 4, 2017

@bradfitz could you please help explaining this if it is expected?

@cznic
Copy link
Contributor

@cznic cznic commented May 4, 2017

Some DBs do not support unsigned integers. Rejecting uint64 >= 1<<63 prevents them become indistinguishable from int64s < 0. If you need to insert such int64 anyway, you have to explicitly convert in on input to int64 and convert it back to uint64 on output - and take care to never insert a signed integer into the same column.

@bradfitz bradfitz changed the title not allowing values in range [2^64 -1 - 2^63] in sql library for uint64 database/sql: not allowing values in range [2^64 -1 - 2^63] in sql library for uint64 May 4, 2017
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented May 4, 2017

This dates back to the beginning of the database/sql package where we decided to only support int64 (not uint64) for simplicity:

https://golang.org/pkg/database/sql/driver/#Value

We decided we could re-evaluate it in the future. The future is here.

@kardianos?

@bradfitz bradfitz added this to the Go1.10 milestone May 4, 2017
@kardianos
Copy link
Contributor

@kardianos kardianos commented May 4, 2017

Cl for go1.9 should enable drivers that want to support it to do so

https://go-review.googlesource.com/c/38533/

@kardianos
Copy link
Contributor

@kardianos kardianos commented May 4, 2017

This is really a duplicate of a number of issues that want to expand the supported types.
Duplicate of #18417 .

It is my plan to allow drivers to support these types starting with go1.9.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.