Documentation Home
MySQL 8.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.2Mb
PDF (A4) - 40.3Mb
Man Pages (TGZ) - 262.0Kb
Man Pages (Zip) - 367.6Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


MySQL 8.4 Reference Manual  / ...  / Data Types  / Spatial Data Types  /  Spatial Data Types

13.4.1 Spatial Data Types

MySQL has spatial data types that correspond to OpenGIS classes. The basis for these types is described inSection 13.4.2, “The OpenGIS Geometry Model”.

Some spatial data types hold single geometry values:

  • GEOMETRY

  • POINT

  • LINESTRING

  • POLYGON

GEOMETRY can store geometry values of any type. The other single-value types (POINT,LINESTRING, andPOLYGON) restrict their values to a particular geometry type.

The other spatial data types hold collections of values:

  • MULTIPOINT

  • MULTILINESTRING

  • MULTIPOLYGON

  • GEOMETRYCOLLECTION

GEOMETRYCOLLECTION can store a collection of objects of any type. The other collection types (MULTIPOINT,MULTILINESTRING, andMULTIPOLYGON) restrict collection members to those having a particular geometry type.

Example: To create a table namedgeom that has a column namedg that can store values of any geometry type, use this statement:

CREATE TABLE geom (g GEOMETRY);

Columns with a spatial data type can have anSRID attribute, to explicitly indicate the spatial reference system (SRS) for values stored in the column. For example:

CREATE TABLE geom (    p POINT SRID 0,    g GEOMETRY NOT NULL SRID 4326);

SPATIAL indexes can be created on spatial columns if they areNOT NULL and have a specific SRID, so if you plan to index the column, declare it with theNOT NULL andSRID attributes:

CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326);

InnoDB tables permitSRID values for Cartesian and geographic SRSs.MyISAM tables permitSRID values for Cartesian SRSs.

TheSRID attribute makes a spatial column SRID-restricted, which has these implications:

Spatial columns with noSRID attribute are not SRID-restricted and accept values with any SRID. However, the optimizer cannot useSPATIAL indexes on them until the column definition is modified to include anSRID attribute, which may require that the column contents first be modified so that all values have the same SRID.

For other examples showing how to use spatial data types in MySQL, seeSection 13.4.6, “Creating Spatial Columns”. For information about spatial reference systems, seeSection 13.4.5, “Spatial Reference System Support”.