This patch corrects two long-standing bugs in CockroachDB which were
confusing both 3rd party tools/ORMs and users:
- the SQL standard type called "CHAR" is supposed to have a default
maximum width of 1 character.
Prior to this patch, CockroachDB did not support this and instead
set no default maximum width on CHAR. This would cause CockroachDB
to fail validating the width of values inserted in tables, fail
to constrain the width of values during casts to CHAR, and report
incorrect information in introspection tables.
- PostgresSQL's dialect distinguishes the table column types TEXT,
CHAR, VARCHAR and a special thing called `"char"` (this is a legacy
PostgreSQL type which is, unfortunately, still used by some
pg_catalog tables).
Prior to this patch, CockroachDB would map all of these types into
the same column type "STRING". In turn this caused them to show
up as "text" in introspection.
While this was not incorrect from the perspective of value
handling (all these types are, indeed, handled with about the same
value semantics in both PostgreSQL and CockroachDB), ORMs
do pay attention to this distinction and become confused if they
see a different type in introspection (e.g. "text") than what
the application model requires (e.g. "char"). The result of this
confusion was to trigger a schema change to adapt the type, which
in turn fails due to missing features in ALTER COLUMN TYPE.
This patch corrects both problems by giving the appropriate default
width to CHAR and preserving the distinction between the various string
types in column descriptors and thus introspection.
Additionally, a width constraint check on collated string columns was
missing. This is now fixed too.
Tables and columns created prior to this patch are unaffected.
Release note (bug fix): CockroachDB now distinguishes "CHAR" and
"VARCHAR" as mandated by the SQL standard and PostgreSQL
compatibility. When a width is not specified (e.g. `CHAR(3)`), the
maximum width of `VARCHAR` remains unconstrained whereas the maximum
width for `CHAR` is now 1 character.
Release note (bug fix): CockroachDB now properly checks the width of
strings inserted in a collated string column with a specified width.
Release note (sql change): CockroachDB now preserves the distinction
between different column types for string values like in PostgreSQL,
for compatibility with 3rd party tools and ORMs.