The character
occupies slightly more, but is the correct one. CPF is a descriptive information that happens to be composed only of digits, one day it may not even be so. You do not have to do calculations with it, it does not quantify anything, so using a numeric type does not make the least sense.
See more .
This can be easily tested in the database:
SELECT pg_column_size(CHAR(11) '999999999'), pg_column_size(VARCHAR(11) '999999999'), pg_column_size(NUMERIC(9,0) '999999999');
See running SQL Fiddle .
Note that CHAR
is what occupies most (which surprises me, this sounds like a bad thing in PostgreSQL), but it's semantically more correct. Think about it, if you know that this information has 11 characters, why would I create a type that size is variable? In normal databases this should be the most economical since it does not need any control metadata, I do not know why PostgreSQL does this. In another database you can give a different result. Would not it be better to use a general solution?
Curiously, using VARCHAR
is a premature optimization.