We have E-Commerce Products table in our Production Database, which has image url column as VARCHAR(200). But sometimes size of image url will be more than 200 which causes failure in Insertion/Updation.
To avoid this can I keep length of VARCHAR to some large value like 1000 or 2000?. By doing this will it affect my query performance by any chance?
Also I'm using Hibernate in my Application to Connect to Mariadb
Failing with these errors
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
Caused by: java.sql.SQLException: Data too long for column 'url' at row 1
Note
Simply make the column TEXT
(64KB max) and hope that you never exceed that.
You won't be able to include the column in a regular index. But you should probably consider FULLTEXT
and MATCH
for searching.
For VARCHAR
here are several cutoffs for various reasons: 40, 191, 255, 767, 3072, and maybe others. The depend on row format, version number, character set, etc. Some of those numbers are bytes, some are characters.
TEXT
and VARCHAR
each have a short (1-4 bytes) "length" field plus the number of bytes necessary for the data. This should not be a concern.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.