I am designing a table which stores 5 digit US zipcodes without extensions. It looks like the leading contenders are CHAR(5)
and MEDIUMINT (5) UNSIGNED ZEROFILL
. Reference:
- Mysql Datatype for US Zip (Postal Codes)
- What is the best column type for a United States ZIP code?
- Padding the beginning of a mysql INT field with zeroes
I plan on going with CHAR(5) for reasons described by Is it a good idea to use an integer column for storing US ZIP codes in a database?. EDIT-As such, using ZEROFILL
is not an answer, so please do not ask me to use ZEROFILL
or close this question and refer to a previous answer which says to use ZEROFILL
.
Next, I want to ensure that (5) characters are always stored, and if less are provided, then either the query produces an error, or it is left padded with zeros (and not right-padded with spaces). My intent is to prevent zipcode "3101" from ever existing in the database, and ensure that it must be "03101". Note that I am not asking how to make a PHP application left pad the zipcodes with zeros.