Return the correct collation for temporal results#602
Closed
dbussink wants to merge 1 commit intomysql:trunkfrom
Closed
Return the correct collation for temporal results#602dbussink wants to merge 1 commit intomysql:trunkfrom
dbussink wants to merge 1 commit intomysql:trunkfrom
Conversation
When functions like `GREATEST`, `LEAST` and `COALESCE` return a temporal result, the collation is not set to `binary` as expected. The collation for temporal types normally is always `binary` which is the case for fields and for functions inheriting from `Item_temporal_func`. The comparison functions mentioned here though don't inherit from that and can return various types. Internally they do set the numeric collation correctly, but at the protocol level (and for what the `COLLATION` function returns), it is translated to the binary collation. This translation does not happen before this change for the given functions, so we add it here. Before: ``` mysql> select collation(date'2010-01-01'); +-----------------------------+ | collation(date'2010-01-01') | +-----------------------------+ | binary | +-----------------------------+ 1 row in set (0.00 sec) mysql> select collation(greatest(date'2010-01-01', date'2009-01-01')); +---------------------------------------------------------+ | collation(greatest(date'2010-01-01', date'2009-01-01')) | +---------------------------------------------------------+ | latin1_swedish_ci | +---------------------------------------------------------+ 1 row in set (0.00 sec) ``` After: ``` mysql> select collation(date'2010-01-01'); +-----------------------------+ | collation(date'2010-01-01') | +-----------------------------+ | binary | +-----------------------------+ 1 row in set (0.00 sec) mysql> select collation(greatest(date'2010-01-01', date'2009-01-01')); +---------------------------------------------------------+ | collation(greatest(date'2010-01-01', date'2009-01-01')) | +---------------------------------------------------------+ | binary | +---------------------------------------------------------+ 1 row in set (0.00 sec) ``` Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
This was referenced Feb 21, 2025
|
Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment: |
Author
|
I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it. |
|
Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When functions like
GREATEST,LEASTandCOALESCEreturn a temporal result, the collation is not set tobinaryas expected.The collation for temporal types normally is always
binarywhich is the case for fields and for functions inheriting fromItem_temporal_func.The comparison functions mentioned here though don't inherit from that and can return various types. Internally they do set the numeric collation correctly, but at the protocol level (and for what the
COLLATIONfunction returns), it is translated to the binary collation.This translation does not happen before this change for the given functions, so we add it here.
Before:
After:
This issue applies to all supported MySQL versions, starting from 8.0.x and later at least.