Common SQL Errors

MySQL Error 3229 ER_GROUPING_ON_TIMESTAMP_IN_DST - How to Fix Non-Deterministic Grouping

Galaxy Team
August 8, 2025

MySQL raises error 3229 when you GROUP BY a TIMESTAMP column that can be ambiguous during daylight-saving-time transitions.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 3229 ER_GROUPING_ON_TIMESTAMP_IN_DST?

MySQL error 3229 ER_GROUPING_ON_TIMESTAMP_IN_DST occurs when a query groups by a TIMESTAMP that overlaps a daylight-saving-time change, making results non-deterministic. Convert the column to UTC or cast to DATE before grouping to resolve the issue.

Error Highlights

Typical Error Message

ER_GROUPING_ON_TIMESTAMP_IN_DST

Error Type

Semantic Error

Language

MySQL

Symbol

having DST. Please consider switching to UTC for this query. ER_GROUPING_ON_TIMESTAMP_IN_DST was added in 5.7.27.

Error Code

3229

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 3229 ER_GROUPING_ON_TIMESTAMP_IN_DST?

MySQL error 3229 appears when a query groups by a TIMESTAMP or DATETIME column while the server time zone observes daylight saving time (DST).

Because the same wall-clock time can occur twice during the DST switch, MySQL cannot guarantee deterministic grouping and therefore aborts the statement.

What Causes This Error?

Grouping by a TIMESTAMP that crosses the DST boundary triggers ambiguity when the session or global time_zone is not UTC.

Derived tables, views, DISTINCT, and ORDER BY clauses that implicitly group by temporal columns can also surface the error if those columns hold DST-affected values.

How to Fix ER_GROUPING_ON_TIMESTAMP_IN_DST

Convert all relevant timestamps to UTC with CONVERT_TZ or set the session time_zone to +00:00 before running the GROUP BY.

Alternatively, cast the column to DATE or YEAR if day-level or year-level granularity is acceptable, removing DST ambiguity.

Common Scenarios and Solutions

Analytics dashboards that group sign-up events by hour fail after autumn DST rollover. Switching the query to GROUP BY DATE(CONVERT_TZ(created_at,'SYSTEM','UTC')) restores stability.

Partitioned ETL jobs that aggregate by TIMESTAMP in local time break on DST boundaries. Running the job under SET time_zone='UTC' resolves the crash.

Best Practices to Avoid This Error

Store and query all timestamps in UTC to make grouping deterministic across time zones.

Always cast to DATE, YEAR, or explicit UTC when grouping temporal data that does not need full timestamp precision.

Related Errors and Solutions

Errors 1292, 1366, and 1299 also stem from invalid or ambiguous datetime values. Handling time zones consistently prevents them alongside 3229.

Common Causes

Common Causes of ER_GROUPING_ON_TIMESTAMP_IN_DST

Grouping by a TIMESTAMP column in a session using a non-UTC time zone that observes DST.

Aggregations in views or subqueries that implicitly group on temporal columns spanning the DST switch.

Legacy code that mixes server default time_zone with explicit time zone conversions.

ETL batches executed with different time_zone settings between steps, causing inconsistent grouping.

Related Errors

MySQL Error 1292 - Incorrect datetime value

Raised when a datetime string cannot be parsed. Ensure valid formats and correct time zones.

MySQL Error 1366 - Incorrect string value

Occurs on invalid character set conversions, including malformed datetime strings.

MySQL Error 1299 - Invalid ON UPDATE clause for TIMESTAMP

Appears when an automatic timestamp column conflicts with explicit defaults or time zones.

FAQs

Does switching to UTC affect existing data?

No. CONVERT_TZ only changes the representation in the query result. Stored values remain unchanged unless an UPDATE is issued.

Can I disable the error instead?

Not directly. MySQL prevents non-deterministic grouping for data integrity. You must adjust the query or time zone.

Will SET sql_mode='' bypass error 3229?

sql_mode settings do not influence this check. The server enforces deterministic grouping regardless of mode.

How does Galaxy help?

Galaxy highlights non-UTC GROUP BY patterns and suggests safe rewrites with its context-aware AI copilot, reducing run-time failures.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo