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: Support SQL placeholder parameters inside array literals #23238

Closed
myartsev opened this issue Dec 24, 2017 · 1 comment
Closed

database/sql: Support SQL placeholder parameters inside array literals #23238

myartsev opened this issue Dec 24, 2017 · 1 comment

Comments

@myartsev
Copy link

@myartsev myartsev commented Dec 24, 2017

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

go version go1.9.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

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

What did you do?

v := 1
_, err := db.Exec("SELECT * FROM foo WHERE an_array @> '{$1}';", v)

What did you expect to see?

Query successfully executes without an arror

What did you see instead?

pq: invalid input syntax for integer: "$1"

When inside an array literal, SQL placeholder parameters do not get evaluated and are passed as-is to the query.
I end up wrapping the query with fmt to make it work.

v := 1
_, err := db.Exec(fmt.Sprintf("SELECT * FROM foo WHERE an_array @> '{%d}';", v))
@myartsev myartsev changed the title Support SQL placeholder parameters inside array literals database/sql: Support SQL placeholder parameters inside array literals Dec 24, 2017
@dominikh
Copy link
Member

@dominikh dominikh commented Dec 24, 2017

Go does not look at the contents of the query. The query is passed to a driver, which itself usually just passes it to the database server. What you're seeing is a limitation by PostgreSQL.

Closing as not a Go issue.

@dominikh dominikh closed this Dec 24, 2017
@golang golang locked and limited conversation to collaborators Dec 24, 2018
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
3 participants
You can’t perform that action at this time.