1
type User struct {
    Email     string `json:"email"`
    Password  string `json:"password"`
}

db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("email: ", reflect.TypeOf(usr.Email)) //string
    fmt.Println("salt: ", reflect.TypeOf(salt))       //[]uint8
    fmt.Println("hash: ", reflect.TypeOf(hash))       //string

    sql := `INSERT INTO public."Users" (email, password, salt) VALUES ($1, $2, $3)`

    _, err = db.Exec(sql, usr.Email, hash, salt)

throws error: "pq: invalid byte sequence for encoding "UTF8": 0x97"
my table: "email" type: TEXT, "password" type: TEXT, "salt" type: smallint[] (thinking this might be the cause of the error but I am not sure what to use instead)

2
  • Maybe salt column is a string? Try string(salt) Commented Aug 25, 2020 at 21:26
  • salt column is smallint[], I can't transform the whole array or it will be a high cost when it comes time to transform and use the []uint8 to login. Commented Aug 25, 2020 at 21:39

1 Answer 1

1

PostgreSQL bytea = []unit8 Golang

changed type and issue was resolved!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.