Repository navigation
Description
Issue description
PostgresDriver.createFullType() appends (length) for any column that has length set, without checking whether the type accepts a length. The driver already declares which types do - withLengthColumnTypes - and uuid is (correctly) not among them. So @Column({ type: "uuid", length: 36 }) renders as uuid(36), which is not a valid PostgreSQL type.
CockroachDriver has the same shape. MysqlDriver, OracleDriver and SqlServerDriver are unaffected, because they route through getColumnLength(), whose type switch returns "" for types that take no length.
Expected Behavior
A length on a type that does not support one is ignored, so the rendered type stays uuid - consistent with the other drivers, and with the driver's own withLengthColumnTypes declaration.
Actual Behavior
The rendered type is uuid(36). Schema comparison then treats the column as permanently changed, and generated/synchronized DDL emits ALTER TABLE ... TYPE uuid(36), which fails to parse.
Steps to reproduce
Smallest form, straight against the driver:
const dataSource = new DataSource({ type: "postgres", /* ... */ });
dataSource.driver.createFullType({ type: "uuid" }); // "uuid" ✔
dataSource.driver.createFullType({ type: "uuid", length: "36" }); // "uuid(36)" ✘Via an entity:
@Entity()
export class Example {
@PrimaryGeneratedColumn("uuid")
id: string;
@Column({ type: "uuid", length: 36 })
ownerId: string;
}synchronize / migration:generate then produces uuid(36) DDL.
Root cause
driver/postgres/PostgresDriver.ts - createFullType() reads column.length directly:
let type = column.type;
if (column.length) {
type += "(" + column.length + ")";
}and getColumnLength() is a passthrough with no type awareness:
getColumnLength(column): string {
return column.length ? column.length.toString() : "";
}Compare the drivers:
| Driver | createFullType uses |
Guarded? |
|---|---|---|
| mysql | getColumnLength() (type switch → "" for unsupported) |
yes |
| oracle | getColumnLength() |
yes |
| sqlserver | getColumnLength() |
yes |
| postgres | column.length directly |
no |
| cockroachdb | column.length directly |
no |
Suggested fix
Gate the append on the list the driver already maintains:
if (column.length && this.withLengthColumnTypes.indexOf(column.type as ColumnType) !== -1) {
type += "(" + column.length + ")";
}or give getColumnLength() the same type awareness the mysql driver's has and use it, which would fix cockroachdb by the same change.
Why it matters beyond a stray option
It removes the only way to express a uuid column width portably. MySQL has no uuid type, so type: "uuid" normalizes to varchar, and MysqlDriver.getColumnLength returns 36 only when generationStrategy === "uuid" - a plain (non-generated) uuid column falls through to the generic varchar default of 255. Setting length: 36 on the entity is the natural fix for that, and it works on MySQL - but the same entity then renders uuid(36) on PostgreSQL, so a codebase targeting both dialects cannot use it.
My Environment
| Dependency | Version |
|---|---|
| Operating System | macOS (Darwin 25.5.0), also reproduced in Linux CI |
| Node.js | 24.15.0 |
| typeorm | 1.1.0 |
| Database | PostgreSQL 18 |
Activity
tada5hi commentedon Jul 29, 2026
Correction to the report above, before anyone spends time on it: the entity-level repro I gave is wrong.
EntityMetadataValidatoralready rejects alengthon a type that does not support one, so@Column({ type: "uuid", length: 36 })never reaches DDL generation on postgres,initialize()throws first:(verified against 1.1.0 with postgres 18). The query runners also only read a length back for types in
withLengthColumnTypes, so no introspectedTableColumnarrives in that state either.What remains is narrower than I claimed:
createFullTypeis unguarded when called directly, and postgres/cockroachdb differ from mysql/oracle/sqlserver in that respect. My cross-driver table also over-stated the difference, mysql'sgetColumnLengthreturnscolumn.lengthfirst when set too; the reason mysql is fine is thatuuidnormalizes tovarchar(which does take a length) beforecreateFullTypesees it.So this is a consistency/defense-in-depth fix rather than a user-facing bug. PR #12742 has it, scoped that way, feel free to close both if the extra branch is not worth carrying.
fix(driver): do not render a length for types that accept none
fix(driver): do not render a length for types that accept none