使用pgx.copyfrom或pgx插入GIS几何后几何。
我找到了从
使用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),
)
这使我
"ERROR: Invalid endian flag value encountered. (SQLSTATE XX000)"
使用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()
我得到这个错误
Error processing batch insert - parse error - invalid geometry (SQLSTATE XX000)
db创建脚本
CREATE TABLE IF NOT EXISTS public.test_db
(
first_name text COLLATE pg_catalog."default",
location geometry
)
非常感谢您
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论