简体   繁体   中英

MySQL spatial query

I had a normal table. Now i added a spatial column

ALTER TABLE roadData ADD pt POINT ;

and now my table has null values : 在此处输入图片说明

Now in MySQL tutorial insert statement is used:

INSERT INTO geom VALUES (ST_GeomFromText('POINT(1 1)'));

but i want to to do it in already existing table removing null values and insert point data based on Latitude and Longitude give in each row. Like

INSERT INTO pt VALUES (ST_GeomFromText('POINT(latitude longitude)'));

and also make a spatial index. How can I do it?

That's an UPDATE STATEMENT and not an INSERT STATEMENT , try this:

UPDATE geom t
SET t.pt = ST_GeomFromText(CONCAT('POINT(',t.longitude,t.latitude,')'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM