This is something like xxxxx-xxxx, so it is recommended varchar(10).
If you want to check the syntax of the values ββin the database, you can create a type domainfor zip codes.
CREATE DOMAIN zipcode varchar(10)
CONSTRAINT valid_zipcode
CHECK (VALUE ~ '[A-Z0-9-]+');
You can look at this site that offers this regular expression:
(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)
But you have to check if this works for regex syntax PostgreSQL.
source
share