View video tutorial

MYSQL POINT

MYSQL

MySQL POINT is a spatial data type that represents a single location in a coordinate system, defined by an X and a Y coordinate.

MySQL POINT


➔ This is useful for geographic information systems (GIS), which store location data such as GPS coordinates (latitude and longitude).

➔ A POINT value is essentially a collection of two floating-point values ​​X and Y, where X usually corresponds to longitude and Y to latitude.

Create table:

Example

/* Create table */
CREATE TABLE mylocations (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255),
    coordinates POINT NOT NULL
);

Copy the code and try it out practically in your learning environment.


Insert value:

Example

/* Insert values */
INSERT INTO mylocations (name, coordinates)
VALUES ('The Eiffel Tower', Point(48.8584, 2.2945));

Copy the code and try it out in your learning environment.


Describe table structure:

Example

/*  Check table structure  */
DESCRIBE mylocations;

Copy the code and try it out practically in your learning environment.


Table structure:
Field Type Null Key Default Extra
id int(11) NO PRI auto_increment
name varchar(255) YES
coordinates point NO

Query value:

To extract individual X (longitude) and Y (latitude) coordinates, the ST_X() and ST_Y() functions should be used.

Example

/* Retrieving Coordinates */
SELECT name, ST_X(coordinates) AS longitude, ST_Y(coordinates) AS latitude
FROM mylocations;

Copy the code and try it out practically in your learning environment.