Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default varchar length is 255, not 256. Why ?

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using openJPA with apache derby.

If I do not specify the actual width of the varchar field, it automatically
maps a String field to a varchar(255).

My question: why 255, and not 256 (since 256 is a power of two) ?
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing since the count is 0 based. 0-255 = 256 possible values.
 
Bill Cruise
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The length of the varchar is stored as a byte by the RDBMS. This makes the possible range of 8-bit values 0-255.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic