I've found the way to make a bulk insert with classic postgres types from this post and it works like a charm. But for whatever reason, i struggle to make it work when trying to insert geometry points:
using pgx.CopyFromRows
rows := [][]interface{}{
{"John", "ST_SetSRID(ST_MakePoint(1.23,2.34), 4326)"},
{"Jane", "ST_SetSRID(ST_MakePoint(1.10,2.12), 4326)"},
}
// GetSession return a *pgxpool.Pool
copyCount, err := postgres.GetSession().CopyFrom(
context.Background(),
pgx.Identifier{"test_db"},
[]string{"first_name", "location"},
pgx.CopyFromRows(rows),
)
this gives me back
"ERROR: Invalid endian flag value encountered. (SQLSTATE XX000)"
using pgx.Batch:
batch := &pgx.Batch{}
batch.Queue("insert into people(first_name, location) values($1, $2)", "Bob", "ST_SetSRID(ST_MakePoint(1.23,1.34), 4326)")
batch.Queue("insert into people(first_name, location) values($1, $2)", "John", "ST_SetSRID(ST_MakePoint(1.23,1.34), 4326)")
batchResult := postgres.GetSession().SendBatch(context.Background(), batch)
_, err := batchResult.Exec()
if err != nil {
return rest_errors.NewInternalServerError("Error processing batch insert", err)
}
batchResult.Close()
I get this error
Error processing batch insert - parse error - invalid geometry (SQLSTATE XX000)
db creation script
CREATE TABLE IF NOT EXISTS public.test_db
(
first_name text COLLATE pg_catalog."default",
location geometry
)
Thank you so much