Error when inserting a point into MariaDB.
yemzz opened this issue · 1 comments
yemzz commented
Hello! I have this problem. I populated the database using PointFromText and select queries work correctly. But I can't insert a new Point into the table.
_, err := tx.ExecContext(ctx, `
INSERT INTO localities (
title,
coords
)
VALUES (?, ST_GeomFromWKB(?))
`,
locality.Title,
wkb.Value(locality.Coords),
)
Error 4079: Illegal parameter data type char for operation 'st_geometryfromwkb'
paulmach commented
There have been recent changes to this. See the ewkb readme for information on how to read/write from maria db.
The following two options worked for me
coord := orb.Point{1, 2}
// as WKB in hex format
data := wkb.MustMarshalToHex(coord)
db.Exec("INSERT INTO geodata(geom) VALUES (ST_GeomFromWKB(UNHEX(?), 4326))", data)
// relying on the raw encoding
db.Exec("INSERT INTO geodata(geom) VALUES (?)", ewkb.ValuePrefixSRID(coord, 4326))