I would like to see a mention in the documentation what is the default
for N if it is not specified.
If I remember correctly for CHAR it is usually 1.
For varchar the default varies between DBMS products often being the
highest allowable N for VARCHAR
but it can be also 1 (I think this is the case in MSSQL) or it could be
even disallowed to use varchar without precision.
With the present day computing systems I think the most logical way
would be to define type TEXT (MySql, Postgres) or STRING (Java)
that only has a system defined upperbound on the length.
Then varchar(n) could be seen as a shorthand for TEXT CHECK(LENGTH(COL)
<= N)
and char as a shorthand for TEXT CHECK(LENGTH(COL) = N) (although this
does not perform the automatic right-padding).
- rami
For me, anybody that still uses CHAR(..) is doing so for backward
compatibility. I don't see any reason why you should use it in a new
application.
Therefore, I don't plan to spend too much time improving the
compatibility, unless there is an important "real world use case". As
far as I understand, you had a look at the feature more from a
theoretical viewpoint, and not so much as a practical problem in a
real existing application, right?
Regards,
Thomas
The main reason was to save storage space while keeping the
implementation simple. If the spaces are added (padding), then either
it needs to be done when inserting (which means the spaces are stored
in the database file, which takes a lot of space), or the number of
spaces needs to be kept in memory somewhere, in which case the
implementation would be more complex (spaces are returned but not
stored). That's why I choose not to pad the spaces.
Regards,
Thomas