mysqlvarcharmysql-5.7

Why/how am I able to exceed the configured length of a varchar in MySQL? [my mistake, I can't]


[Edit: my mistake, read the wrong column for the type, the one I'm inserting into is LONGTEXT, not varchar(190)] I am working with an application that stores the majority of its information in a MySQL database (MySQL server 5.7). One particular value I'm looking at has a 255 character limit enforced by the GUI but, when I looked at that column in the table where it's stored, it's set to varchar(190). I confirmed that I can enter 255-character values in the GUI and that they are not truncated, as I expected.

How can a varchar(190) column store >190 characters? Are there any consequences to doing it this way?

I read 11.4.1 The CHAR and VARCHAR Types and it states that anything over the limit should be truncated.


Solution

  • The answer is that I can't.

    Misread the column types because that column is varchar(255) when the application builds the schema in PostgreSQL. It's LONGTEXT* in MySQL, which explains why I was able to get past the 190 characters. I tried inserting my 230 char test string into the varchar(190) column and it throws an error, as expected.

    Need more coffee.

    * Not sure why LONGTEXT, when the application GUI limits input to 255 characters, but I'll need to ask the people who built it.