How to Fix MySQL Error 3520 (ER_SRS_NOT_CARTESIAN)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 3520 when a flat-plane math function runs on curved map data. Fix it by converting the spatial reference ID to a flat system or changing functions. The database engine marks this failure with the symbol ER_SRS_NOT_CARTESIAN and SQLSTATE 22S00. It blocks the query so your app does not save bad distance or area numbers. Teams see this issue when they upgrade databases or mix map tools with standard tables. Why mysql error 3520 happens in your database MySQL supports two mai

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You get mysql error 3520 when a flat-plane math function runs on curved map data. Fix it by converting the spatial reference ID to a flat system or changing functions.

The database engine marks this failure with the symbol ER_SRS_NOT_CARTESIAN and SQLSTATE 22S00. It blocks the query so your app does not save bad distance or area numbers. Teams see this issue when they upgrade databases or mix map tools with standard tables.

Why mysql error 3520 happens in your database

MySQL supports two main types of map systems for spatial data. A Cartesian system treats the world like a flat sheet of graph paper. A geographic system models the world as a round globe using latitude and longitude.

Each spatial column or shape holds a Spatial Reference System ID, or SRID. SRID zero represents a flat, unitless Cartesian plane in the database engine. Many other SRID numbers represent round earth models or specific regional map grids.

The error message states that a function only works for Cartesian spatial reference systems. It then notes that one argument uses a non-Cartesian SRID. The database engine stops the query before doing flat math on round coordinates.

This failure often appears after a database upgrade from older versions. Older engines ignored SRID rules and ran flat math on all coordinate pairs. Newer engines check the SRID catalog and reject mismatched spatial math right away.

How to find the bad spatial reference ID

Start by reading the full error log from your failed query. The message names the exact spatial function and the SRID number that caused the stop. Check which columns or input values feed into that specific function.

Run a read-only query in a safe test session to inspect the column SRID. You can check the system catalog views to see the SRID definition. Look at whether the SRID is geographic or projected onto a flat grid.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Sometimes the table column has no SRID lock, yet the incoming data carries a globe SRID. Check the app code or data import pipeline that builds the geometry objects. Look for map libraries that tag every new shape with a default GPS coordinate system.

Do not grant full admin rights to developers who need to inspect production tables. Give them read-only access to the schema metadata and sample rows. Make sure data masking rewrites emails, phone numbers, card numbers, and national IDs in query results.

How to fix the query and prevent future errors

You have three safe ways to fix this spatial mismatch in production. First, swap the flat-plane function for one that supports round earth math. Many distance and containment checks have versions built for geographic coordinates.

Second, transform the round earth data into a projected flat grid before running the math. Use the built-in spatial transform tool to shift the shape into a regional Cartesian SRID. Pick a flat projection that matches the local area of your map data.

Third, if your data is just flat drawing coordinates, set its SRID to zero. Do not use a globe SRID for floor plans, game boards, or simple charts. Update your table schema or query input so the SRID matches the flat data type.

Test your fix on a staging database before running changes in production. Updating an SRID on a large table can drop and rebuild spatial indexes. Plan schema updates during low traffic hours so you do not lock active tables.

Inspect every MySQL query and response in flight

Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.

First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.

Frequently asked questions

What does SQLSTATE 22S00 mean with ER_SRS_NOT_CARTESIAN?

SQLSTATE 22S00 signals an invalid argument in a spatial math operation. Together with code 3520, it means you passed round earth coordinates into a flat-plane function.

Can I fix error 3520 by changing the SRID to zero?

Only change the SRID to zero if your coordinates represent flat points. If you force GPS coordinates into SRID zero, distance and area math will return wrong numbers.

Why did my spatial query break after a MySQL upgrade?

Older database versions ignored SRID types and treated all shapes as flat planes. Newer versions check the SRID catalog and block flat math on geographic map systems.

The query runs. The emails stay hidden.