-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot use net.ParseIP(c.IP()) (type net.IP) as type pgtype.Inet in field value #180
Comments
I'm not sure how gorm works. But the following reads an package main
import (
"database/sql"
"fmt"
"log"
"github.com/jackc/pgtype"
_ "github.com/jackc/pgx/v4/stdlib"
)
func main() {
db, err := sql.Open("pgx", "")
if err != nil {
log.Fatal(err)
}
defer db.Close()
var ip pgtype.Inet
err = db.QueryRow("select '127.0.0.1'::inet").Scan(&ip)
if err != nil {
log.Fatal(err)
}
fmt.Println(ip)
} |
yeah trying to do this with GORM
|
I don't know anything about GORM, but it looks like your trying to scan into |
so what do i do? do i not use GORM to insert and get records that has IP address? here is GORM doc https://gorm.io/docs/index.html what do i do please? will appreciate your advice |
I don't know. Like I said I don't use GORM or any other Go ORM for that matter. I typically write my own SQL and mapping code more or less by hand. |
here is my model
I am trying to parse the ip address which is in string format to type
pgtype.Inet
in postgresql databaselike this when inserting into the database
we are told to parse the ip using
net
package but this is error from thatI have also tried using
net
package for the modelbut kept getting this error
so how do we store
inet
values inside postgresql using GORM?The text was updated successfully, but these errors were encountered: