I am using golang with postgres. I want to delete users from my table by passing in the Id for that user. When I run the code below I always get true. Even when I pass in a ID that does not exist in the table. Is that normal? Does DB.Exec return err if the user ID is not in the database?
func DeleteUser(ID int){
    err = nil
    _, err := DB.Exec("DELETE FROM Users WHERE user_id=$1", ID)
    if err == nil {
        return true
    }
    return false
}
                Try this
func DeleteUser(ID int){
    err = nil
    res, err := DB.Exec("DELETE FROM Users WHERE user_id=$1", ID)
    if err == nil {
       count, err := res.RowsAffected()  
       if err == nil {
          /* check count and return true/false */
       }
    }
    return false
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With