Click here to Skip to main content
15,566,615 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to do an update to a field, directory through Workbench as well as .NET using the MySQL Drivers for something like :

Update MyTable SET MyField='W ' WHERE ID=12

So I am trying to updating a field with the letter W and a space.

When I go to retrieve it via a SELECT using workbench or .NET, I am just getting 'W' - no space. Its like it is automatically trimming the field!

Even if I trail with 5 spaces - it still returns a length of 1, not 6 using
SELECT Length(MyField) FROM MyTable WHERE ID=12

If I pad with spaces to the left of the W, the string remains intact so its only trimming from the right. I dont want it to trim at all!

Its a Char(200) utf8mb4 field.


Any help would be great. Thanks in advance.

What I have tried:

Adding more spaces, post and pre the character. Googling for a reason, but no one else seems to having this issue, which I do not believe. Maybe I am using the wrong terminology in locating the answer but its driving me nuts!

Using a Medium Text (and I presume Long text, but definitely Medium Text, not just Char) the space is stored and retrieved.
Posted
Updated 22-Aug-22 4:48am
v2

1 solution

Found it:
MySQL :: MySQL 8.0 Reference Manual :: 11.3.2 The CHAR and VARCHAR Types[^]

CHAR remove the spaces unless specified. I best use VARCHAR for this I guess. What a headache!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900