Du kan bruge pgx bibliotek til det:
filename := "foo.csv"
dbconn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
panic(err)
}
defer dbconn.Release()
f, err := os.Open(filename)
if err != nil {
panic(err)
}
defer func() { _ = f.Close() }()
res, err := dbconn.Conn().PgConn().CopyFrom(context.Background(), f, "COPY csv_test FROM STDIN (FORMAT csv)")
if err != nil {
panic(err)
}
fmt.Print(res.RowsAffected())