• MySQL知识库 :: error messages
  • Error: 1252 All parts of a SPATIAL index must be NOT NULL

  • Discussion

    MySQL has data types which correspond to OpenGIS classes. Some of these types hold single geometry values: GEOMETRY, POINT, LINESTRING, POLYGON. These column data types can be used for storing and indexing spatial values. For indexing a table based on a spatial column, it's necessary that spatial columns that are to be indexed must be declared NOT NULL when creating or altering a table. For example, notice that NOT NULL must be specific for 'location' field below:

    CREATE TABLE table1
    (
      place VARCHAR(200) NOT NULL,
      location POINT NOT NULL,
      SPATIAL INDEX(location),
      PRIMARY KEY(place)
    )ENGINE=MyISAM;
    
    INSERT INTO table1(place,location) 
       VALUES ('Point1', GeomFromText('POINT(20 43)'));