Skip to content

Defaults not respected for tstzrange columns #11990

Closed

Description

@clintonb

Issue description

TypeORM generates an invalid migration for tstzrange defaults

Expected Behavior

await queryRunner.query(`
    ALTER TABLE "receiving_events"
    ADD "sys_period" tstzrange NOT NULL DEFAULT tstzrange(current_timestamp, null)
`);

Actual Behavior

await queryRunner.query(`
    ALTER TABLE "receiving_events"
    ALTER COLUMN "sys_period"
    SET DEFAULT now()
`);

Steps to reproduce

  1. Add a tstzrange column with a default:
  @Column({
    type: 'tstzrange',
    insert: false,
    update: false,
    default: () => 'tstzrange(current_timestamp, null)',
  })
  sysPeriod: string;
  1. Generate a migration.

My Environment

Dependency Version
Operating System macOS 26.2
Node.js version 24.12.0
Typescript version 5.5.3
TypeORM version 0.3.22

Additional Context

I want to use temporal_tables to manage this columns values.

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, but I don't know how to start. I would need guidance.

Activity

  1. clintonb commented on Feb 14, 2026

    @clintonb
    ContributorAuthor

    I've confirmed this also fails with 0.3.28.

  2. clintonb commented on Feb 14, 2026

    @clintonb
    ContributorAuthor

    I was able to get this to work by updating my default to exactly match what PostgresDriver.ts normalizes to:

      @Column({
        type: 'tstzrange',
        insert: false,
        update: false,
        default: () => 'tstzrange(now(), NULL)',
      })
      sysPeriod: string;
    • CURRENT_TIMESTAMP was replaced by now()
    • NULL must be uppercase.

    This was a waste of many hours!

  3. gioboa commented on Feb 14, 2026

    @gioboa
    Collaborator

    Thanks for your report @clintonb
    I'll look at that in these days

  4. gioboa commented on Feb 14, 2026

    @gioboa
    Collaborator

    @clintonb can you create a reproduction repo/steps for that please?

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions