Skip to content

database/sql: Scan results are of wrong type when Query has no args #27828

Closed
@ComaVN

Description

@ComaVN

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

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

$ docker run --rm golang:1.11.0 go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build662937076=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I tried to use Rows.Scan to read fields of an sql result row into variables of type interface{}

See https://github.com/ComaVN/gosqltypespoc

What did you expect to see?

I expect integer sql types to be read as go type int64, or at least, the go type should be the same whatever the query looks like.

What did you see instead?

SELECT 123 WHERE ? = 1 returns int64: 123
SELECT 123 WHERE 1 = 1 returns []uint8: []byte{0x31, 0x32, 0x33}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions