• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Strange Behavior of varchar(255)

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declare a column as varchar(2) - assume my input is ab - only 2 characters are allowed. When i try to insert one more character it throws error.

Declare a column as varchar(4) - assume my input is abcd - only 4 characters are allowed. When i try to insert one more character it throws error.

Declare a column as varchar(255) - however i can able to input abcdabcdabcd...more than 255 characters

I couldn't understand how many alphabetical small case characters a varchar(255) can hold. if it can hold many...why the same is not applicable for varchar(2) or varchar(4)

Please kindly clarify in detail.

Thanks.
 
Saloon Keeper
Posts: 2679
335
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which database and version are you working with?
 
Joseph Michael
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mysql version 8 Innodb
 
Master Rancher
Posts: 4208
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you creating your 256 character string?

Is it just lots of 'abcd' or have you stuck spaces at the end?
 
Joseph Michael
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdab
cdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdab
cdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd
abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd
 
Dave Tolls
Master Rancher
Posts: 4208
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And when you query it back from the database?
Does it match, or has it been truncated?

I assume this is the same DB that was rejecting overlong values for the VARCHAR(2) and (4) fields?
 
Danger, 10,000 volts, very electic .... tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!