-
I have a problem of find records in tablbe by hex string in bytea column when use argument.
What a right way to use this value as argument for bytea? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You should be able to use a package main
import (
"context"
"encoding/hex"
"log"
"os"
"github.com/jackc/pgx/v5"
)
func main() {
ctx := context.Background()
conn, err := pgx.Connect(ctx, os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatal(err)
}
defer conn.Close(ctx)
b, err := hex.DecodeString("01020304")
if err != nil {
log.Fatal(err)
}
var isEqual bool
err = conn.QueryRow(ctx, `select '\x01020304'::bytea = $1::bytea`, b).Scan(&isEqual)
if err != nil {
log.Fatal(err)
}
log.Println("isEqual:", isEqual)
}
|
Beta Was this translation helpful? Give feedback.
You should be able to use a
[]byte
as anbytea
parameter.hex.DecodeString
should have done what you want.