Using the MyISAM
storage engine in MySQL, I'd like to enforce the uniqueness of a POLYGON
column in a table. Basically if I attempt to insert a duplicate, I want it to result in an error, or simply be ignored. With traditional column types this can be accomplished using the UNIQUE
keyword, but with a spatial column this leads to errors like:
ERROR 1170 (42000): BLOB/TEXT column 'bounding_box' used in key specification without a key length
coming from this table definition:
CREATE TABLE IF NOT EXISTS quadrants (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
bounding_box POLYGON NOT NULL UNIQUE,
centroid POINT NOT NULL UNIQUE,
SPATIAL KEY bb_idx(bounding_box),
SPATIAL KEY centroid_idx(centroid)
) ENGINE=MyISAM;
Is it possible to enforce uniqueness for spatial datatypes in MySQL?
EDIT: It has been suggested that this is a duplicate of MySQL error: key specification without a key length but I believe it is different. That question and its answers make no mention of spatial datatypes. I'm left to infer that POLYGON
is actually stored as BLOB
and thus subject to similar constraints. But I still don't know if there is any other way to enforce uniqueness of POLYGON
---or whether there are practical workarounds if that is not the case.
The other question addresses the same error, but in a different enough context that I feel a separate question is useful.