Skip to content

PostgresDriver.createFullType appends a length to types that do not take one (uuid(36)) #12741

Open

Description

@tada5hi

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

  1. tada5hi commented on Jul 29, 2026

    @tada5hi
    ContributorAuthor

    Correction to the report above, before anyone spends time on it: the entity-level repro I gave is wrong.

    EntityMetadataValidator already rejects a length on a type that does not support one, so @Column({ type: "uuid", length: 36 }) never reaches DDL generation on postgres, initialize() throws first:

    TypeORMError: Column ownerId of Entity LengthProbe does not support length property.
    

    (verified against 1.1.0 with postgres 18). The query runners also only read a length back for types in withLengthColumnTypes, so no introspected TableColumn arrives in that state either.

    What remains is narrower than I claimed: createFullType is 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's getColumnLength returns column.length first when set too; the reason mysql is fine is that uuid normalizes to varchar (which does take a length) before createFullType sees 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.

  2. added 2 commits that reference this issue on Jul 29, 2026
    826c828
    2515fb1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions