Skip to content

Instantly share code, notes, and snippets.

@nickretallack
Created December 12, 2014 01:55
Show Gist options
  • Save nickretallack/cd808e68381d3c31f5ba to your computer and use it in GitHub Desktop.
Save nickretallack/cd808e68381d3c31f5ba to your computer and use it in GitHub Desktop.
Can't bind hex values in go sql?
package main
import (
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
)
type Result struct {
Testhex string
}
func main(){
var err error
db, err := sqlx.Connect("postgres", "dbname=testhex sslmode=disable")
if err != nil {
panic(err)
}
var result Result
err = db.Get(&result, "select testhex from testhex where testhex = $1", `\x123456`)
if err != nil {
panic(err) // no rows?
}
}
create table testhex (testhex bytea);
insert into testhex (testhex) values ('\x123456');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment