MySQL INSERT / UPDATE in POINT column

I am trying to populate my database with the geographic locations of my country. One of my tables has 4 fields: ID [PK], latitude. longitude ande geoPoint

EDIT `SCDBs`.`Punto_Geografico`;

SET @lat = 18.469692;

SET @lon = -63.93212;

SET @g = 'POINT(@lat @lon)';

UPDATE Punto_Geografico SET latitude = @lat, longitude =@lon, geoPoint =@g WHERE idpunto_geografico = 0;

im gets the following error: Error code: 1416 Unable to get the geometry object from the data sent to the GEOMETRY field.

I am sure that the "geoPoint" field is a POINT field with a spatial index. I havenโ€™t lost anything .14

+7
source share
2 answers

Try to do this without assigning your values โ€‹โ€‹to the server values. Especially if they contain function calls. MySQL considers the contents of variables as plain text and wonโ€™t see that there is a function call there.

UPDATE ... SET latitude=18, longitute=-63, geoPoint=POINT(18 -63) WHERE ...
+9
source

You need to use this syntax:

UPDATE ... SET latitude=18, longitute=-63, geoPoint=GeomFromText('POINT(18 -63)') WHERE ...
+10

All Articles