docs/reference/rules/ban-char-field.md
Diagnostic Category: lint/safety/banCharField
Since: vnext
Sources:
Using CHAR(n) or CHARACTER(n) types is discouraged.
CHAR types are fixed-length and padded with spaces, which can lead to unexpected behavior when comparing strings or concatenating values. They also waste storage space when values are shorter than the declared length.
Use VARCHAR or TEXT instead for variable-length character data.
CREATE TABLE "core_bar" (
"id" serial NOT NULL PRIMARY KEY,
"alpha" char(100) NOT NULL
);
code-block.sql:1:1 lint/safety/banCharField ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! CHAR type is discouraged due to space padding behavior.
> 1 │ CREATE TABLE "core_bar" (
│ ^^^^^^^^^^^^^^^^^^^^^^^^^
> 2 │ "id" serial NOT NULL PRIMARY KEY,
> 3 │ "alpha" char(100) NOT NULL
> 4 │ );
│ ^^
5 │
i CHAR types are fixed-length and padded with spaces, which can lead to unexpected behavior.
i Use VARCHAR or TEXT instead for variable-length character data.
CREATE TABLE "core_bar" (
"id" serial NOT NULL PRIMARY KEY,
"alpha" varchar(100) NOT NULL
);
{
"linter": {
"rules": {
"safety": {
"banCharField": "error"
}
}
}
}