MySQL raises ER_BOOST_GEOMETRY_CENTROID_EXCEPTION (error 3039, SQLSTATE HY000) when a spatial centroid operation is attempted on an empty geometry.
ER_BOOST_GEOMETRY_CENTROID_EXCEPTION (MySQL error 3039) signals that ST_Centroid cannot compute a centroid because the input geometry is empty. Validate or filter out empty geometries before calling ST_Centroid to resolve the issue.
ER_BOOST_GEOMETRY_CENTROID_EXCEPTION
MySQL error 3039 occurs when the server tries to execute ST_Centroid or a related spatial function on a geometry that contains no points. The Boost.Geometry library returns an exception, which MySQL surfaces as ER_BOOST_GEOMETRY_CENTROID_EXCEPTION.
The error is accompanied by SQLSTATE HY000 and appears in MySQL 5.7.5 and later. Fixing it quickly is important because spatial queries that fail mid-transaction can roll back work, break GIS applications, or slow analytics pipelines.
The most common trigger is passing an empty geometry object to ST_Centroid, ST_Envelope, or ST_Transform. When the geometry collection has zero coordinates, Boost.Geometry cannot determine a centroid.
The error can also surface when spatial indexes reference rows that were later updated to empty geometries, or when data pipelines import NULL geometries that are coerced into empty values.
Validate the geometry before calling ST_Centroid. Use ST_IsEmpty or a WHERE clause to filter out empty rows. If empty shapes are valid, decide on a fallback centroid such as POINT(0,0) or skip those records.
Wrap the centroid call in a CASE expression to handle empties gracefully, or apply NOT NULL and CHECK constraints to stop empty geometries from entering the table.
Bulk imports from shapefiles often include placeholder geometries. Run an UPDATE to delete or replace them before spatial analytics.
Application code that constructs polygons from user clicks may accidentally send an empty POLYGON() when no vertices are selected. Add client-side validation or a server-side trigger to block the insert.
Add CHECK (NOT ST_IsEmpty(geom)) constraints or trigger-based validations so only valid geometries enter the table.
Use Galaxy’s AI copilot to scan queries for ST_Centroid calls lacking ST_IsEmpty guards, and share vetted SQL snippets in a Galaxy Collection for team reuse.
ER_BOOST_GEOMETRY_EMPTY_INPUT is raised when input geometries are empty for other operations such as ST_Area. ER_GEOMETRY_FORMAT is triggered by invalid WKT strings. The fixes follow the same pattern: validate input and constrain data quality.
Calling ST_Centroid on an empty POINT(), LINESTRING(), or POLYGON().
Importing shapefiles that convert NULL coordinates into empty geometries.
Spatial index corruption pointing to deleted rows.
User-generated data where no vertices were supplied.
Raised when other Boost spatial functions receive empty geometries. Validate inputs as with centroid errors.
Occurs when WKT or WKB strings are malformed. Use ST_GeomFromText with strict mode to detect problems early.
Triggered when MySQL encounters an unsupported geometry type. Upgrade client libraries or convert data to supported types.
Yes. Use a WHERE NOT ST_IsEmpty(geom) filter or a CASE expression so empties do not cause failures while retaining original data.
Not necessarily. It usually means the geometry itself is empty, but you should still run ANALYZE TABLE or rebuild indexes if queries remain slow.
MySQL 5.7.5 and later, including all 8.x versions, surface ER_BOOST_GEOMETRY_CENTROID_EXCEPTION when Boost.Geometry cannot compute a centroid.
Galaxy’s SQL editor highlights ST_Centroid calls without emptiness checks and lets teams endorse corrected queries, reducing the chance of runtime failures.