MySQL POINT Data Type Guide

In MySQL, POINT is a geographic spatial data type used to store the longitude and latitude coordinates of a point. It is useful for representing locations and performing spatial operations.

To create a column of POINT type, you can use the following syntax:

CREATE TABLE table_name (
    column_name POINT
);

To insert and update values in a POINT column, you need to use the POINT function, which takes two parameters: longitude and latitude. For example:

INSERT INTO table_name (column_name) VALUES (POINT(经度, 纬度));
UPDATE table_name SET column_name = POINT(经度, 纬度) WHERE condition;

You can use the ST_X and ST_Y functions to extract the longitude and latitude from a POINT value.

SELECT ST_X(column_name) AS 经度, ST_Y(column_name) AS 纬度 FROM table_name;

In addition, MySQL also offers several spatial functions that can be used to handle POINT data types, such as calculating the distance between two points, determining if a point is within a polygon, and so on. These functions include ST_Distance, ST_Within, and others.

It is important to note that the use of geographic spatial data types requires enabling the corresponding extensions in MySQL, such as spatial or geo.

bannerAds