Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What I don’t understand is the totally arbitrary cargo cult nvarchar limits. Why 255?


It's an arbitrary but common one used in SQL Server. If the example used 128, you'd ask "why 128?" If it was 64, 50, 100, or any other number, you'd still ask. What is the right number? String lengths should come from business rules and the data domain but, when those don't exist (or someone is creating a fake table just to show an example), they borrow from other examples or existing schemas. It's clearly not the point of the article to come up with the absolute best and universally satisfying table design for orders.


As a sibling comment said, optimizing for size. However, since in ut8mb4 (the standard for Postgres, and modern MySQL) each char may take up to 4 bytes to store, the updated version of this would be VARCHAR(63).

If you can guarantee you’ll only store ASCII, you can safely use 255.

This is also probably a premature optimization for practically anyone to be fair. Even at 1 billion rows, you’ve only added 1 GiB of overhead, and at that scale that’s a small percentage of the overall size.


255 is the maximum array size representable with an unsigned byte. It is possible that old relational DBs could optimize arrays with sizes < 256.

I remember that the ancient Pascal dialect I used in college had max array sizes of 255 because they used a single byte for the size.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: