Created
December 12, 2014 01:55
-
-
Save nickretallack/cd808e68381d3c31f5ba to your computer and use it in GitHub Desktop.
Can't bind hex values in go sql?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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