Skip to content

MDEV-9343 Copying from YEAR to DATE result in '0000-00-00' #3978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 10.11
Choose a base branch
from

Conversation

HazemRawi
Copy link

When converting YEAR values to DATE/DATETIME, explicitly set month and day to zero (e.g., 2000 → 2000-00-00). Validate against SQL modes:

  • Allow 2000-00-00 if NO_ZERO_IN_DATE is disabled
  • Reject if NO_ZERO_IN_DATE is enabled
  • The Jira issue number for this PR is: MDEV-9343

Description

This fix explicitly targets YEAR to DATE or DATETIME conversions (setting month=0, day=0).
Queries involving YEAR(), MONTH(), or DAY() functions will change its behavior because they rely on the same conversion logic (number_to_datetime_or_date, str_to_datetime_or_date_body) used for date parsing.

Release Notes

The server now preserves the year value when converting YEAR to DATE or DATETIME, resulting in YYYY-00-00.

How can this PR be tested?

Run ./mtr main.type_date

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@CLAassistant
Copy link

CLAassistant commented Apr 15, 2025

CLA assistant check
All committers have signed the CLA.

@svoj svoj added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Apr 15, 2025
@svoj svoj requested a review from abarkov April 18, 2025 11:36
@HazemRawi
Copy link
Author

Ping 👀

@svoj
Copy link
Contributor

svoj commented Apr 28, 2025

@HazemRawi Hi! This pull request was assigned to @abarkov for review. MDEV-9434 received Critical priority, which means it is constantly on radar.

In the meantime, please rebase on top of fresh 10.11, it contains fix for massive main.timezone failure. Also please check buildbot status, there're failures that are very likely caused by this patch.

Copy link
Contributor

@svoj svoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As requested in the comment: rebase and check bb failures.

When converting YEAR values to DATE/DATETIME, explicitly set month and day
to zero (e.g., 2000 → 2000-00-00). Validate against SQL modes:
- Allow `2000-00-00` if `NO_ZERO_IN_DATE` is disabled
- Reject if `NO_ZERO_IN_DATE` is enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.
Development

Successfully merging this pull request may close these issues.

3 participants