Skip to content

Conversation

@zhangxu19830126
Copy link
Contributor

Problem:
When updating TEXT columns with CONCAT operations in UPDATE statements, the system throws an error: 'Can't cast column from TEXT type to CHAR type because of one or more values in that column. Src length 260 is larger than Dest length 255'.

Root Cause:
The strToStr function was performing length validation for all string type casts, including when casting from TEXT (which has no length limit) to CHAR/VARCHAR types. This caused errors when TEXT values exceeded the target type's length limit, even though TEXT should be allowed to store strings of any length.

Solution:

  • Added source type check in strToStr function to detect when source is TEXT
  • Skip length validation when casting from TEXT to CHAR/VARCHAR types
  • This allows TEXT columns to be updated with CONCAT operations that may exceed CHAR/VARCHAR length limits
  • The storage layer will handle the actual type correctly

Changes:

  • Modified strToStr() in func_cast.go to skip length check for TEXT source
  • Added comprehensive unit tests in func_cast_test.go covering:
    • TEXT to CHAR conversions with length exceeding target limit
    • TEXT to VARCHAR conversions with length exceeding target limit
    • NULL value handling
    • Multiple values scenarios
    • Verification that non-TEXT types still perform length validation

Test: Test_strToStr_TextToCharVarchar

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #23176

What this PR does / why we need it:

Fix bug.

Problem:
When updating TEXT columns with CONCAT operations in UPDATE statements,
the system throws an error: 'Can't cast column from TEXT type to CHAR type
because of one or more values in that column. Src length 260 is larger than
Dest length 255'.

Root Cause:
The strToStr function was performing length validation for all string type
casts, including when casting from TEXT (which has no length limit) to
CHAR/VARCHAR types. This caused errors when TEXT values exceeded the target
type's length limit, even though TEXT should be allowed to store strings
of any length.

Solution:
- Added source type check in strToStr function to detect when source is TEXT
- Skip length validation when casting from TEXT to CHAR/VARCHAR types
- This allows TEXT columns to be updated with CONCAT operations that may
  exceed CHAR/VARCHAR length limits
- The storage layer will handle the actual type correctly

Changes:
- Modified strToStr() in func_cast.go to skip length check for TEXT source
- Added comprehensive unit tests in func_cast_test.go covering:
  * TEXT to CHAR conversions with length exceeding target limit
  * TEXT to VARCHAR conversions with length exceeding target limit
  * NULL value handling
  * Multiple values scenarios
  * Verification that non-TEXT types still perform length validation

Test: Test_strToStr_TextToCharVarchar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants