How to Fix MySQL Error 3155 (ER_NUMERIC_JSON_VALUE_OUT_OF_RANGE)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 3155 when a JSON number is too big or too small to cast. You fix it by changing the target type to hold larger numbers or cleaning the JSON data. The database engine uses the symbol ER_NUMERIC_JSON_VALUE_OUT_OF_RANGE and SQLSTATE 22003 for this fault. It stops the query right away so your app does not store broken math. Why mysql error 3155 happens in your database JSON documents let apps store numbers of almost any size without strict rules. Standard database columns use

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 3155 when a JSON number is too big or too small to cast. You fix it by changing the target type to hold larger numbers or cleaning the JSON data.

The database engine uses the symbol ER_NUMERIC_JSON_VALUE_OUT_OF_RANGE and SQLSTATE 22003 for this fault. It stops the query right away so your app does not store broken math.

Why mysql error 3155 happens in your database

JSON documents let apps store numbers of almost any size without strict rules. Standard database columns use fixed byte sizes for whole numbers and decimals. When a query extracts a JSON number and casts it, the engine checks the size. If the JSON number goes past the limit of the target type, the query fails.

The database returns a clear message for this event. It reports an out of range JSON value for the cast from the column at a specific row. This tells your team which column and row hold the bad number.

This issue often starts when an upstream app sends a huge timestamp or ID. A signed target type might also reject a negative number when you cast to an unsigned type. Even a decimal cast will fail if the integer part exceeds your defined precision.

How to find the bad row in production

Start by reading the full error message in your app log. The message gives you the column name and the row number that broke the cast. Keep in mind that the row number points to the result set order, not the primary key.

You can inspect the raw JSON values in that column without running the cast. Filter the table by checking the length or text pattern of the extracted JSON path. This lets you find the oversized numbers without triggering the 3155 failure again.

DPoP (Demonstration of Proof-of-Possession) + JSON Web Tokens (JWT): architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

When you check production data, keep strict data privacy rules in place. A JSON column often holds user details like emails, phone numbers, card numbers, or national IDs. Use data masking so the system rewrites matched fields in results during your check.

How to fix the cast and prevent future errors

Once you find the oversized number, you have two main ways to fix the problem. First, you can widen the target type in your cast statement. For example, move from a standard integer type to a larger big integer or a wider decimal.

Second, you can fix the bad value inside the JSON document itself. Sometimes a bug in an upstream app writes a bad number into the payload. You can update the broken JSON key in that row and add checks to your app code.

Do not turn off strict SQL mode just to hide the error. Turning off strict checks lets the database clip large numbers down to the maximum allowed value. That silent clipping corrupts your records and causes hard bugs later on.

If you use generated columns or functional indexes on JSON paths, check their definitions too. An index that casts a JSON field to a narrow number type will block new writes. Widening the cast in the generated column definition will let valid inserts work again.

Add wire guardrails and masking beside MySQL

Database grants and TLS setup decide who can reach MySQL. Even so, an open session can run broad updates or read raw personal data from allowed tables. In practice, hoop.dev sits inline in the wire protocol beside the database as a sidecar for your MySQL. On every production query an agent or engineer sends, hoop.dev decides to pass, mask, block, or escalate it for human review.

With hoop.dev MySQL support, guardrails refuse bad queries before they run or hold risky calls for approval, while data masking rewrites matched sensitive values in result rows in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for GDPR, HIPAA, and PCI DSS programs. Read the docs and source on GitHub.

Frequently asked questions

What does SQLSTATE 22003 mean with error 3155?

SQLSTATE 22003 is the standard code for a numeric value out of range. Along with code 3155, it means the JSON number specifically failed a cast operation.

Can negative numbers in JSON trigger error 3155?

Yes, casting a negative JSON number to an unsigned integer type triggers this error. Change the cast to a signed integer type if your data includes negative values.

Why did an insert fail with error 3155 when I wrote no cast?

Your table likely has a virtual or stored generated column that casts a JSON path. When you insert a new row, the engine runs that hidden cast and fails.

The query runs. The emails stay hidden.