Skip to content

fix(postgres): handle timestamptz persistence/hydration correctly - #11774

Merged
alumni merged 5 commits into
typeorm:masterfrom
Minishlink:patch-1
Jan 30, 2026
Merged

alumni merged 5 commits into
typeorm:masterfrom
Minishlink:patch-1

Conversation

@Minishlink

@Minishlink Minishlink commented Nov 17, 2025 •

Copy link
Copy Markdown
Contributor

Description of change

This includes 'timestamptz' as type for values which are Date and should be serialized/deserialized in/from the cache.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000 (searched for timestamptz)
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change

Summary by CodeRabbit

  • New Features

    • Added support for PostgreSQL timestamptz columns, enabling proper handling of timezone-aware timestamps.
  • Tests

    • Updated Postgres tests to cover timestamptz handling, enable query caching in test runs, and add runtime assertions verifying Date values and equality.

@coderabbitai

coderabbitai Bot commented Nov 17, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds support for Postgres timestamptz by treating it like existing timestamp/datetime in PostgresDriver persistence and hydration; tests and an entity gain a timestampTz: Date field and queries use caching in related tests.

Changes

Cohort / File(s) Summary
Postgres driver update
src/driver/postgres/PostgresDriver.ts
Added handling for column type timestamptz in preparePersistentValue and prepareHydratedValue, mapping to/from Date/string like other timestamp types.
Tests — Postgres column types
test/functional/database-schema/column-types/postgres/column-types-postgres.ts
Enabled query caching for test connections, replaced findOneBy with cached findOne({ where: ..., cache: true }), added and asserted timestampTz Date field checks, and adjusted index expectations.
Test entity addition
test/functional/database-schema/column-types/postgres/entity/PostWithOptions.ts
Added public property timestampTz: Date with @Column("timestamptz") to the PostWithOptions entity.
Manifest
package.json
(Touched by test adjustments)

Sequence Diagram(s)

sequenceDiagram
    participant App as Application / Tests
    participant Driver as PostgresDriver
    participant DB as Postgres

    Note over App,Driver: Persisting entity with timestamptz
    App->>Driver: preparePersistentValue(value, columnMetadata)
    alt column.type == "timestamptz"
        Driver-->>Driver: convert Date -> DB string (ISO) 
    else other timestamp types
        Driver-->>Driver: existing timestamp handling
    end
    Driver->>DB: execute INSERT/UPDATE with converted value

    Note over DB,Driver: Hydration path
    DB-->>Driver: returns timestamptz string
    Driver->>Driver: prepareHydratedValue(dbValue, columnMetadata)
    alt column.type == "timestamptz"
        Driver-->>Driver: convert string -> Date object
    else other timestamp types
        Driver-->>Driver: existing timestamp handling
    end
    Driver->>App: returns hydrated entity with Date in `timestampTz`
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Multiple test updates plus a driver change; logic is small but spans driver behavior and test expectations.
  • Areas to pay attention:
    • Date/string conversion edge cases (timezones, null/undefined).
    • Tests’ use of caching and updated query shapes.
    • Entity column decorator correctness.

Suggested reviewers

  • alumni

Poem

🐰
I hopped through code both quick and spry,
Found timestamptz beneath the sky,
I wrapped its moments, near and far,
Now dates arrive as shining star ✨🕰️

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(postgres): 'timestamptz' type persistence/hydration' directly and specifically describes the main change: adding persistence/hydration support for the timestamptz type in PostgreSQL, which matches the file modifications in PostgresDriver.ts and the new test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Nov 17, 2025 •

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm/typeorm@11774
    

commit: f4e0706

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help, can you add a test to cover this case please?

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
test/functional/database-schema/column-types/postgres/column-types-postgres.ts (1)

408-419: Consider adding a comment to clarify the cache-testing pattern.

The double findOne calls test cache behavior: the first populates the cache from the database, and the second retrieves from the cache to verify proper serialization/deserialization of Date objects. While the pattern is clear to those familiar with cache testing, a brief comment would improve readability.

Apply this diff to add a clarifying comment:

                await postRepository.save(post)
+                // First query populates the cache from database
                await postRepository.findOne({
                    where: {
                        id: 1,
                    },
                    cache: true,
                })
+                // Second query loads from cache to verify serialization/deserialization
                const loadedPost = (await postRepository.findOne({
                    where: {
                        id: 1,
                    },
                    cache: true,
                }))!
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 317a5ec and d20a175.

📒 Files selected for processing (2)
  • test/functional/database-schema/column-types/postgres/column-types-postgres.ts (3 hunks)
  • test/functional/database-schema/column-types/postgres/entity/PostWithOptions.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-27T20:50:10.364Z
Learnt from: alumni
Repo: typeorm/typeorm PR: 11581
File: docs/docs/drivers/postgres.md:23-23
Timestamp: 2025-07-27T20:50:10.364Z
Learning: The correct data source type for Aurora PostgreSQL in TypeORM is `aurora-postgres`, not `aurora-data-api-pg`. The `aurora-data-api-pg` driver was renamed to `aurora-postgres` according to the CHANGELOG.md. This is defined in the DatabaseType union type and AuroraPostgresConnectionOptions interface.

Applied to files:

  • test/functional/database-schema/column-types/postgres/entity/PostWithOptions.ts
🧬 Code graph analysis (1)
test/functional/database-schema/column-types/postgres/entity/PostWithOptions.ts (1)
src/decorator/columns/Column.ts (1)
  • Column (134-220)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: tests-linux (20) / mysql_mariadb
  • GitHub Check: tests-linux (20) / mssql
  • GitHub Check: tests-linux (20) / mongodb
  • GitHub Check: tests-linux (20) / oracle
  • GitHub Check: tests-linux (18) / postgres (17)
  • GitHub Check: tests-linux (18) / sap
  • GitHub Check: tests-linux (18) / mysql_mariadb_latest
  • GitHub Check: tests-linux (18) / postgres (14)
  • GitHub Check: tests-linux (18) / sqljs
  • GitHub Check: tests-linux (18) / mongodb
  • GitHub Check: tests-linux (18) / oracle
  • GitHub Check: tests-linux (18) / sqlite
  • GitHub Check: tests-linux (18) / better-sqlite3
  • GitHub Check: tests-linux (18) / mysql_mariadb
  • GitHub Check: tests-linux (18) / mssql
  • GitHub Check: tests-windows / sqljs
  • GitHub Check: tests-windows / sqlite
  • GitHub Check: tests-windows / better-sqlite3
  • GitHub Check: formatting
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
test/functional/database-schema/column-types/postgres/entity/PostWithOptions.ts (1)

46-47: LGTM! Clean addition of timestamptz column.

The new timestampTz column follows the same pattern as existing timestamp columns and correctly uses the timestamptz type (PostgreSQL alias for timestamp with time zone).

test/functional/database-schema/column-types/postgres/column-types-postgres.ts (3)

18-18: Good addition to test cache behavior.

Enabling caching is essential for testing the timestamptz persistence/hydration through the cache layer, which is the focus of this PR.


403-403: LGTM!

The initialization of timestampTz follows the same pattern as other timestamp fields.


429-440: Excellent addition of instanceof Date assertions!

The instanceof Date checks at lines 432, 436, and 440 are crucial for verifying that timestamp values are properly hydrated as Date objects when loaded from cache, not just as strings or plain objects. This directly validates the core objective of this PR—ensuring timestamptz (and other timestamp types) are correctly serialized/deserialized through the cache layer.

The assertions for the new timestampTz field (lines 437-440) properly test both value equality and type correctness.

@Minishlink

Copy link
Copy Markdown
Contributor Author

Sure, I added a specific test for timestamptz and fixed the existing test case which was not really testing persistence/hydration since the data was not fetched from the cache

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Minishlink it looks great 👏

@G0maa G0maa left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Minishlink, could you update the branch?

connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
enabledDrivers: ["postgres"],
cache: true,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why enable this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll assume two things, so correct me if I'm wrong.

  1. timestamptz column types were not cached correctly as the type was not in preparePersistentValue and prepareHydrateValue, so this PR fixes that.
  2. The cache: true is to verify caching works for said column type.

If both assumptions are true then I'd prefer if caching was enabled separately in another test, since this particular file tests column types, not caching.

I've looked at other column-types-x.ts files to see if they have caching enabled and they don't.

See:
https://github.com/typeorm/typeorm/blob/master/test/functional/database-schema/column-types/mysql/column-types-mysql.ts#L16-L19
https://github.com/typeorm/typeorm/blob/master/test/functional/database-schema/column-types/cockroachdb/column-types-cockroach.ts#L23-L27

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're right. I assumed that persistence/hydration was linked to cache?

@G0maa G0maa Nov 24, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused too 🤔

I am assuming that persistence/hydration works regardless of caching. i.e. data serialization/deserialization form/to database/ORM.

But then, why does timestamptz work without caching and fails when caching? i.e. if the issue is serialization/deserialization it should fail in both cases.

It might be that this logic here is executed somewhere which fixes the issue when caching is not used.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a small sample here, should fail if you enable caching, should success if you disable caching.

@alumni alumni Nov 24, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're right. I assumed that persistence/hydration was linked to cache?

Nope. Cache has nothing do to with hydration.

Could we undo this line and merge master to see that the tests are still passing?

It should affect anything now, but we don't want any additional functionality affecting the result of the test in the future.

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 24, 2025 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to f4e0706

CategorySuggestion                                                                                                                                    Impact
General
Remove redundant database query

Remove the redundant findOne call as its result is discarded, and only the
second identical call is used.

test/functional/database-schema/column-types/postgres/column-types-postgres.test.ts [407-418]

-await postRepository.findOne({
-    where: {
-        id: 1,
-    },
-    cache: true,
-})
 const loadedPost = (await postRepository.findOne({
     where: {
         id: 1,
     },
     cache: true,
 }))!
  • Apply / Chat
Suggestion importance[1-10]: 4

__

Why: The suggestion correctly identifies a redundant findOne call in a test, which was likely left by mistake, and its removal improves code clarity and removes an unnecessary database query.

Low
  • More

Previous suggestions

Suggestions
CategorySuggestion                                                                                                                                    Impact
General
Remove redundant database query

Remove the first of two identical and consecutive postRepository.findOne calls,
as its result is discarded and the operation is redundant.

test/functional/database-schema/column-types/postgres/column-types-postgres.ts [407-418]

-await postRepository.findOne({
-    where: {
-        id: 1,
-    },
-    cache: true,
-})
 const loadedPost = (await postRepository.findOne({
     where: {
         id: 1,
     },
     cache: true,
 }))!
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies a redundant database call in a test file, which was likely introduced by a copy-paste error. Removing it improves code quality and clarity.

Low

Removed caching from testing column types in PostgreSQL.
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 24, 2025 •

Copy link
Copy Markdown

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Impact
General
✅ Remove redundant database query
Suggestion Impact:The entire test file was deleted in this commit, which includes removing the redundant database query that was identified in the suggestion (lines 408-413 in the original file)

code diff:

@@ -1,554 +1 @@
-import "reflect-metadata"
-import { PostWithOptions } from "./entity/PostWithOptions"
-import { DataSource } from "../../../../../src/data-source/DataSource"
-import {
-    closeTestingConnections,
-    createTestingConnections,
-    reloadTestingDatabases,
-} from "../../../../utils/test-utils"
-import { PostWithoutTypes } from "./entity/PostWithoutTypes"
-import { Post } from "./entity/Post"
 
-describe("database schema > column types > postgres", () => {
-    let connections: DataSource[]
-    before(async () => {
-        connections = await createTestingConnections({
-            entities: [__dirname + "/entity/*{.js,.ts}"],
-            enabledDrivers: ["postgres"],
-        })
-
-        for (const connection of connections) {
-            if (connection.driver.options.type === "postgres") {
-                // We want to have UTC as timezone
-                await connection.query("SET TIME ZONE 'UTC';")
-            }
-        }
-    })
-    beforeEach(() => reloadTestingDatabases(connections))
-    after(() => closeTestingConnections(connections))
-
-    it("all types should work correctly - persist and hydrate", () =>
-        Promise.all(
-            connections.map(async (connection) => {
-                const postRepository = connection.getRepository(Post)
-                const queryRunner = connection.createQueryRunner()
-                const table = await queryRunner.getTable("post")
-                await queryRunner.release()
-
-                const post = new Post()
-                post.id = 1
-                post.name = "Post"
-                post.integer = 2147483647
-                post.int4 = 2147483647
-                post.int = 2147483647
-                post.smallint = 32767
-                post.int2 = 32767
-                post.bigint = "8223372036854775807"
-                post.int8 = "8223372036854775807"
-                post.numeric = "50"
-                post.decimal = "50"
-                post.doublePrecision = 15.357
-                post.float8 = 15.357
-                post.real = 5.5
-                post.float4 = 5.5
-                post.money = "$775,807.07"
-                post.char = "A"
-                post.character = "A"
-                post.varchar = "This is varchar"
-                post.characterVarying = "This is character varying"
-                post.text = "This is text"
-                post.citext = "This is text"
-                post.hstore = "name => Alice, surname => A, age => 30"
-                post.bytea = Buffer.from("This is bytea")
-                post.date = "2017-06-21"
-                post.interval =
-                    "1 year 2 months 3 days 4 hours 5 minutes 6 seconds"
-                post.time = "15:30:00"
-                post.timeWithTimeZone = "15:30:00 PST"
-                post.timetz = "15:30:00 PST"
-                post.timestamp = new Date()
-                post.timestamp.setMilliseconds(0)
-                post.timestampWithTimeZone = new Date()
-                post.timestampWithTimeZone.setMilliseconds(0)
-                post.timestamptz = new Date()
-                post.timestamptz.setMilliseconds(0)
-                post.boolean = true
-                post.bool = false
-                post.enum = "A"
-                post.point = "(10,20)"
-                post.line = "{1,2,3}"
-                post.lseg = "(1,2), (3,4)"
-                post.box = "(1,2),(3,4)" // postgres swaps coordinates in database. This one will be saved like (3,4),(1,2)
-                post.path = "((3,1),(2,8),(10,4))"
-                post.polygon = "((3,1),(2,8),(10,4))"
-                post.circle = "4, 5, 12"
-                post.cidr = "192.168.100.128/25"
-                post.inet = "192.168.100.128"
-                post.macaddr = "08:00:2b:01:02:03"
-                post.macaddr8 = "08:00:2b:01:02:03:04:05"
-                post.bit = "1"
-                post.varbit = "100"
-                post.bitVarying = "00"
-                post.uuid = "0e37df36-f698-11e6-8dd4-cb9ced3df976"
-                post.json = { id: 1, name: "Post" }
-                post.jsonb = { id: 1, name: "Post" }
-                post.jsonpath = '$."name"'
-                post.int4range = "[10,20)"
-                post.int8range = "[200000,500000)"
-                post.numrange = "(10.5,20.2)"
-                post.tsrange = "[2010-01-01 14:30,2010-01-01 15:30)"
-                post.tstzrange =
-                    "[2010-01-01 14:30:00+00,2010-01-01 15:30:00+00)"
-                post.daterange = "[2010-01-01,2010-01-05)"
-                post.int4multirange = "{[10,20),[25,30)}"
-                post.int8multirange = "{[200000,500000),[600000,700000)}"
-                post.nummultirange = "{(10.5,20.2),(30.5,40.2)}"
-                post.tsmultirange =
-                    '{["2010-01-01 14:30:00","2010-01-01 15:30:00"),["2010-01-01 16:30:00","2010-01-01 17:30:00")}'
-                post.tstzmultirange =
-                    '{["2010-01-01 14:30:00+00","2010-01-01 15:30:00+00"),["2010-01-01 16:30:00+00","2010-01-01 17:30:00+00")}'
-                post.datemultirange =
-                    "{[2010-01-01,2010-01-05),[2010-01-10,2010-01-15)}"
-                post.xml =
-                    "<book><title>Manual</title><chapter>...</chapter></book>"
-                post.array = [1, 2, 3]
-                post.simpleArray = ["A", "B", "C"]
-                post.simpleJson = { param: "VALUE" }
-                post.simpleEnum = "A"
-                await postRepository.save(post)
-
-                const loadedPost = (await postRepository.findOneBy({
-                    id: 1,
-                }))!
-                loadedPost.id.should.be.equal(post.id)
-                loadedPost.name.should.be.equal(post.name)
-                loadedPost.integer.should.be.equal(post.integer)
-                loadedPost.int4.should.be.equal(post.int4)
-                loadedPost.int.should.be.equal(post.int)
-                loadedPost.smallint.should.be.equal(post.smallint)
-                loadedPost.int2.should.be.equal(post.int2)
-                loadedPost.bigint.should.be.equal(post.bigint)
-                loadedPost.int8.should.be.equal(post.int8)
-                loadedPost.numeric.should.be.equal(post.numeric)
-                loadedPost.decimal.should.be.equal(post.decimal)
-                loadedPost.doublePrecision.should.be.equal(post.doublePrecision)
-                loadedPost.float8.should.be.equal(post.float8)
-                loadedPost.real.should.be.equal(post.real)
-                loadedPost.float4.should.be.equal(post.float4)
-                loadedPost.money.should.be.equal(post.money)
-                loadedPost.char.should.be.equal(post.char)
-                loadedPost.character.should.be.equal(post.character)
-                loadedPost.varchar.should.be.equal(post.varchar)
-                loadedPost.characterVarying.should.be.equal(
-                    post.characterVarying,
-                )
-                loadedPost.text.should.be.equal(post.text)
-                loadedPost.citext.should.be.equal("This is text")
-                loadedPost.hstore.should.be.equal(
-                    `"age"=>"30", "name"=>"Alice", "surname"=>"A"`,
-                )
-                loadedPost.bytea
-                    .toString()
-                    .should.be.equal(post.bytea.toString())
-                loadedPost.date.should.be.equal(post.date)
-                loadedPost.interval.years.should.be.equal(1)
-                loadedPost.interval.months.should.be.equal(2)
-                loadedPost.interval.days.should.be.equal(3)
-                loadedPost.interval.hours.should.be.equal(4)
-                loadedPost.interval.minutes.should.be.equal(5)
-                loadedPost.interval.seconds.should.be.equal(6)
-                loadedPost.time.should.be.equal(post.time)
-                loadedPost.timeWithTimeZone.should.be.equal("15:30:00-08")
-                loadedPost.timetz.should.be.equal("15:30:00-08")
-                loadedPost.timestamp
-                    .valueOf()
-                    .should.be.equal(post.timestamp.valueOf())
-                // loadedPost.timestampWithTimeZone.getTime().should.be.equal(post.timestampWithTimeZone.getTime());
-                loadedPost.timestamptz
-                    .valueOf()
-                    .should.be.equal(post.timestamptz.valueOf())
-                loadedPost.boolean.should.be.equal(post.boolean)
-                loadedPost.bool.should.be.equal(post.bool)
-                loadedPost.enum.should.be.equal(post.enum)
-                loadedPost.point.should.be.eql({ x: 10, y: 20 })
-                loadedPost.line.should.be.equal(post.line)
-                loadedPost.lseg.should.be.equal("[(1,2),(3,4)]")
-                // loadedPost.box.should.be.equal(post.box); // postgres swaps coordinates in database. This one will be saved like (3,4),(1,2)
-                loadedPost.path.should.be.equal(post.path)
-                loadedPost.polygon.should.be.equal(post.polygon)
-                loadedPost.circle.should.be.eql({ x: 4, y: 5, radius: 12 })
-                loadedPost.cidr.should.be.equal(post.cidr)
-                loadedPost.inet.should.be.equal(post.inet)
-                loadedPost.macaddr.should.be.equal(post.macaddr)
-                loadedPost.macaddr8.should.be.equal(post.macaddr8)
-                loadedPost.bit.should.be.equal(post.bit)
-                loadedPost.varbit.should.be.equal(post.varbit)
-                loadedPost.bitVarying.should.be.equal(post.bitVarying)
-                loadedPost.uuid.should.be.equal(post.uuid)
-                loadedPost.json.should.be.eql(post.json)
-                loadedPost.jsonb.should.be.eql(post.jsonb)
-                loadedPost.jsonpath.should.be.eql(post.jsonpath)
-                loadedPost.int4range.should.be.eql(post.int4range)
-                loadedPost.int8range.should.be.eql(post.int8range)
-                loadedPost.numrange.should.be.eql(post.numrange)
-                loadedPost.tsrange.should.be.eql(
-                    `["2010-01-01 14:30:00","2010-01-01 15:30:00")`,
-                )
-                loadedPost.tstzrange.should.be.eql(
-                    `["2010-01-01 14:30:00+00","2010-01-01 15:30:00+00")`,
-                )
-                loadedPost.daterange.should.be.eql(post.daterange)
-                loadedPost.int4multirange.should.be.eql(post.int4multirange)
-                loadedPost.int8multirange.should.be.eql(post.int8multirange)
-                loadedPost.nummultirange.should.be.eql(post.nummultirange)
-                loadedPost.tsmultirange.should.be.eql(post.tsmultirange)
-                loadedPost.tstzmultirange.should.be.eql(post.tstzmultirange)
-                loadedPost.datemultirange.should.be.eql(post.datemultirange)
-                loadedPost.xml.should.be.equal(post.xml)
-                loadedPost.array[0].should.be.equal(post.array[0])
-                loadedPost.array[1].should.be.equal(post.array[1])
-                loadedPost.array[2].should.be.equal(post.array[2])
-                loadedPost.simpleArray[0].should.be.equal(post.simpleArray[0])
-                loadedPost.simpleArray[1].should.be.equal(post.simpleArray[1])
-                loadedPost.simpleArray[2].should.be.equal(post.simpleArray[2])
-                loadedPost.simpleJson.param.should.be.equal(
-                    post.simpleJson.param,
-                )
-                loadedPost.simpleEnum.should.be.equal(post.simpleEnum)
-
-                table!.findColumnByName("id")!.type.should.be.equal("integer")
-                table!
-                    .findColumnByName("name")!
-                    .type.should.be.equal("character varying")
-                table!
-                    .findColumnByName("integer")!
-                    .type.should.be.equal("integer")
-                table!.findColumnByName("int4")!.type.should.be.equal("integer")
-                table!.findColumnByName("int")!.type.should.be.equal("integer")
-                table!
-                    .findColumnByName("smallint")!
-                    .type.should.be.equal("smallint")
-                table!
-                    .findColumnByName("int2")!
-                    .type.should.be.equal("smallint")
-                table!
-                    .findColumnByName("bigint")!
-                    .type.should.be.equal("bigint")
-                table!
-                    .findColumnByName("numeric")!
-                    .type.should.be.equal("numeric")
-                table!
-                    .findColumnByName("decimal")!
-                    .type.should.be.equal("numeric")
-                table!
-                    .findColumnByName("doublePrecision")!
-                    .type.should.be.equal("double precision")
-                table!
-                    .findColumnByName("float8")!
-                    .type.should.be.equal("double precision")
-                table!.findColumnByName("real")!.type.should.be.equal("real")
-                table!.findColumnByName("float4")!.type.should.be.equal("real")
-                table!.findColumnByName("money")!.type.should.be.equal("money")
-                table!
-                    .findColumnByName("char")!
-                    .type.should.be.equal("character")
-                table!
-                    .findColumnByName("character")!
-                    .type.should.be.equal("character")
-                table!
-                    .findColumnByName("varchar")!
-                    .type.should.be.equal("character varying")
-                table!
-                    .findColumnByName("characterVarying")!
-                    .type.should.be.equal("character varying")
-                table!.findColumnByName("text")!.type.should.be.equal("text")
-                table!
-                    .findColumnByName("citext")!
-                    .type.should.be.equal("citext")
-                table!
-                    .findColumnByName("hstore")!
-                    .type.should.be.equal("hstore")
-                table!.findColumnByName("bytea")!.type.should.be.equal("bytea")
-                table!.findColumnByName("date")!.type.should.be.equal("date")
-                table!
-                    .findColumnByName("interval")!
-                    .type.should.be.equal("interval")
-                table!
-                    .findColumnByName("time")!
-                    .type.should.be.equal("time without time zone")
-                table!
-                    .findColumnByName("timeWithTimeZone")!
-                    .type.should.be.equal("time with time zone")
-                table!
-                    .findColumnByName("timetz")!
-                    .type.should.be.equal("time with time zone")
-                table!
-                    .findColumnByName("timestamp")!
-                    .type.should.be.equal("timestamp without time zone")
-                table!
-                    .findColumnByName("timestampWithTimeZone")!
-                    .type.should.be.equal("timestamp with time zone")
-                table!
-                    .findColumnByName("timestamptz")!
-                    .type.should.be.equal("timestamp with time zone")
-                table!
-                    .findColumnByName("boolean")!
-                    .type.should.be.equal("boolean")
-                table!.findColumnByName("bool")!.type.should.be.equal("boolean")
-                table!.findColumnByName("enum")!.type.should.be.equal("enum")
-                table!.findColumnByName("point")!.type.should.be.equal("point")
-                table!.findColumnByName("line")!.type.should.be.equal("line")
-                table!.findColumnByName("lseg")!.type.should.be.equal("lseg")
-                table!.findColumnByName("box")!.type.should.be.equal("box")
-                table!.findColumnByName("path")!.type.should.be.equal("path")
-                table!
-                    .findColumnByName("polygon")!
-                    .type.should.be.equal("polygon")
-                table!
-                    .findColumnByName("circle")!
-                    .type.should.be.equal("circle")
-                table!.findColumnByName("cidr")!.type.should.be.equal("cidr")
-                table!.findColumnByName("inet")!.type.should.be.equal("inet")
-                table!
-                    .findColumnByName("macaddr")!
-                    .type.should.be.equal("macaddr")
-                table!
-                    .findColumnByName("macaddr8")!
-                    .type.should.be.equal("macaddr8")
-                table!.findColumnByName("bit")!.type.should.be.equal("bit")
-                table!
-                    .findColumnByName("varbit")!
-                    .type.should.be.equal("bit varying")
-                table!
-                    .findColumnByName("bitVarying")!
-                    .type.should.be.equal("bit varying")
-                table!.findColumnByName("uuid")!.type.should.be.equal("uuid")
-                table!.findColumnByName("xml")!.type.should.be.equal("xml")
-                table!.findColumnByName("json")!.type.should.be.equal("json")
-                table!.findColumnByName("jsonb")!.type.should.be.equal("jsonb")
-                table!
-                    .findColumnByName("jsonpath")!
-                    .type.should.be.equal("jsonpath")
-                table!
-                    .findColumnByName("int4range")!
-                    .type.should.be.equal("int4range")
-                table!
-                    .findColumnByName("int8range")!
-                    .type.should.be.equal("int8range")
-                table!
-                    .findColumnByName("numrange")!
-                    .type.should.be.equal("numrange")
-                table!
-                    .findColumnByName("tsrange")!
-                    .type.should.be.equal("tsrange")
-                table!
-                    .findColumnByName("tstzrange")!
-                    .type.should.be.equal("tstzrange")
-                table!
-                    .findColumnByName("daterange")!
-                    .type.should.be.equal("daterange")
-                table!
-                    .findColumnByName("int4multirange")!
-                    .type.should.be.equal("int4multirange")
-                table!
-                    .findColumnByName("int8multirange")!
-                    .type.should.be.equal("int8multirange")
-                table!
-                    .findColumnByName("nummultirange")!
-                    .type.should.be.equal("nummultirange")
-                table!
-                    .findColumnByName("tsmultirange")!
-                    .type.should.be.equal("tsmultirange")
-                table!
-                    .findColumnByName("tstzmultirange")!
-                    .type.should.be.equal("tstzmultirange")
-                table!
-                    .findColumnByName("datemultirange")!
-                    .type.should.be.equal("datemultirange")
-                table!
-                    .findColumnByName("array")!
-                    .type.should.be.equal("integer")
-                table!.findColumnByName("array")!.isArray!.should.be.true
-                table!
-                    .findColumnByName("simpleArray")!
-                    .type.should.be.equal("text")
-                table!
-                    .findColumnByName("simpleJson")!
-                    .type.should.be.equal("text")
-                table!
-                    .findColumnByName("simpleEnum")!
-                    .type.should.be.equal("enum")
-            }),
-        ))
-
-    it("all types should work correctly - persist and hydrate when options are specified on columns", () =>
-        Promise.all(
-            connections.map(async (connection) => {
-                const postRepository = connection.getRepository(PostWithOptions)
-                const queryRunner = connection.createQueryRunner()
-                const table = await queryRunner.getTable("post_with_options")
-                await queryRunner.release()
-
-                const post = new PostWithOptions()
-                post.id = 1
-                post.numeric = "50.00"
-                post.decimal = "50.00"
-                post.char = "AAA"
-                post.character = "AAA"
-                post.varchar = "This is varchar"
-                post.characterVarying = "This is character varying"
-                post.timestamp = new Date()
-                post.timestampWithTimeZone = new Date()
-                post.timestampTz = new Date()
-                post.time = "15:30:13.278"
-                post.timeWithTimeZone = "15:30:13.27801+05"
-                post.int4range = "[2,4)"
-                await postRepository.save(post)
-                await postRepository.findOne({
-                    where: {
-                        id: 1,
-                    },
-                    cache: true,
-                })
-                const loadedPost = (await postRepository.findOne({
-                    where: {
-                        id: 1,
-                    },
-                    cache: true,
-                }))!
-                loadedPost.id.should.be.equal(post.id)
-                loadedPost.numeric.should.be.equal(post.numeric)
-                loadedPost.decimal.should.be.equal(post.decimal)
-                loadedPost.char.should.be.equal(post.char)
-                loadedPost.character.should.be.equal(post.character)
-                loadedPost.varchar.should.be.equal(post.varchar)
-                loadedPost.characterVarying.should.be.equal(
-                    post.characterVarying,
-                )
-                loadedPost.timestamp
-                    .valueOf()
-                    .should.be.equal(post.timestamp.valueOf())
-                loadedPost.timestamp.should.be.instanceof(Date)
-                loadedPost.timestampWithTimeZone
-                    .valueOf()
-                    .should.be.equal(post.timestampWithTimeZone.valueOf())
-                loadedPost.timestampWithTimeZone.should.be.instanceof(Date)
-                loadedPost.timestampTz
-                    .valueOf()
-                    .should.be.equal(post.timestampTz.valueOf())
-                loadedPost.timestampTz.should.be.instanceof(Date)
-                loadedPost.time.valueOf().should.be.equal(post.time.valueOf())
-                loadedPost.timeWithTimeZone
-                    .valueOf()
-                    .should.be.equal(post.timeWithTimeZone.valueOf())
-                loadedPost.int4range
-                    .valueOf()
-                    .should.be.equal(post.int4range.valueOf())
-
-                table!.findColumnByName("id")!.type.should.be.equal("integer")
-                table!
-                    .findColumnByName("numeric")!
-                    .type.should.be.equal("numeric")
-                table!
-                    .findColumnByName("numeric")!
-                    .precision!.should.be.equal(5)
-                table!.findColumnByName("numeric")!.scale!.should.be.equal(2)
-                table!
-                    .findColumnByName("decimal")!
-                    .type.should.be.equal("numeric")
-                table!
-                    .findColumnByName("decimal")!
-                    .precision!.should.be.equal(5)
-                table!.findColumnByName("decimal")!.scale!.should.be.equal(2)
-                table!
-                    .findColumnByName("char")!
-                    .type.should.be.equal("character")
-                table!.findColumnByName("char")!.length!.should.be.equal("3")
-                table!
-                    .findColumnByName("character")!
-                    .type.should.be.equal("character")
-                table!
-                    .findColumnByName("character")!
-                    .length!.should.be.equal("3")
-                table!
-                    .findColumnByName("varchar")!
-                    .type.should.be.equal("character varying")
-                table!
-                    .findColumnByName("varchar")!
-                    .length!.should.be.equal("30")
-                table!
-                    .findColumnByName("characterVarying")!
-                    .type.should.be.equal("character varying")
-                table!
-                    .findColumnByName("characterVarying")!
-                    .length!.should.be.equal("30")
-                table!
-                    .findColumnByName("timestamp")!
-                    .type.should.be.equal("timestamp without time zone")
-                table!
-                    .findColumnByName("timestamp")!
-                    .precision!.should.be.equal(3)
-                table!
-                    .findColumnByName("timestampWithTimeZone")!
-                    .type.should.be.equal("timestamp with time zone")
-                table!
-                    .findColumnByName("timestampWithTimeZone")!
-                    .precision!.should.be.equal(5)
-                table!
-                    .findColumnByName("time")!
-                    .type.should.be.equal("time without time zone")
-                table!.findColumnByName("time")!.precision!.should.be.equal(3)
-                table!
-                    .findColumnByName("timeWithTimeZone")!
-                    .type.should.be.equal("time with time zone")
-                table!
-                    .findColumnByName("timeWithTimeZone")!
-                    .precision!.should.be.equal(5)
-                table!
-                    .findColumnByName("int4range")!
-                    .type.should.be.equal("int4range")
-                table!
-                    .findColumnByName("int4range")!
-                    .isNullable!.should.be.equal(true)
-            }),
-        ))
-
-    it("all types should work correctly - persist and hydrate when types are not specified on columns", () =>
-        Promise.all(
-            connections.map(async (connection) => {
-                const postRepository =
-                    connection.getRepository(PostWithoutTypes)
-                const queryRunner = connection.createQueryRunner()
-                const table = await queryRunner.getTable("post_without_types")
-                await queryRunner.release()
-
-                const post = new PostWithoutTypes()
-                post.id = 1
-                post.name = "Post"
-                post.bit = true
-                post.datetime = new Date()
-                post.datetime.setMilliseconds(0)
-                await postRepository.save(post)
-
-                const loadedPost = (await postRepository.findOneBy({
-                    id: 1,
-                }))!
-                loadedPost.id.should.be.equal(post.id)
-                loadedPost.name.should.be.equal(post.name)
-                loadedPost.bit.should.be.equal(post.bit)
-                loadedPost.datetime
-                    .valueOf()
-                    .should.be.equal(post.datetime.valueOf())
-
-                table!.findColumnByName("id")!.type.should.be.equal("integer")
-                table!
-                    .findColumnByName("name")!
-                    .type.should.be.equal("character varying")
-                table!.findColumnByName("bit")!.type.should.be.equal("boolean")
-                table!
-                    .findColumnByName("datetime")!
-                    .type.should.be.equal("timestamp without time zone")
-            }),
-        ))
-})

Remove the first of two identical and consecutive postRepository.findOne calls,
as its result is discarded and the operation is redundant.

test/functional/database-schema/column-types/postgres/column-types-postgres.ts [407-418]

-await postRepository.findOne({
-    where: {
-        id: 1,
-    },
-    cache: true,
-})
 const loadedPost = (await postRepository.findOne({
     where: {
         id: 1,
     },
     cache: true,
 }))!

[Suggestion processed]

Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies a redundant database call in a test file, which was likely introduced by a copy-paste error. Removing it improves code quality and clarity.

Low
  • More

@alumni alumni left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PostWithOptions entity is reserved for data types that have parameters.

We already had Post.timestamptz and similar tests in test/functional/database-schema/column-types/postgres/column-types-postgres.ts lines 167-169 and 291-293 ("all types should work correctly - persist and hydrate").

So unless I'm missing something, the new test doesn't seem to be testing the change in this PR.

I would add the necessary assertions to the test above (for Post.timestamptz)

@G0maa

G0maa commented Nov 24, 2025

Copy link
Copy Markdown
Collaborator

Hello @Minishlink, you could check my reproduction at https://github.com/G0maa/typeorm-bug-reproduce/blob/43407c7eb6feda7300846e566ec65aab11fc09d0/src/app.ts for this PR,

If you uncomment the cache: true, the bug would happen, it seems for some reason hydrate/persist isn't done correctly when using caching for timestamptz.

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Minishlink thanks for opening this PR.
I'm closing this for now because it's stale and with conflicts, feel free to create a new PR with your improvements. 💪

@Minishlink

Copy link
Copy Markdown
Contributor Author

#11916

@alumni alumni reopened this Jan 30, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

User description

Description of change

This includes 'timestamptz' as type for values which are Date and should be serialized/deserialized in/from the cache.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000 (searched for timestamptz)
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change

Summary by CodeRabbit

  • New Features

    • Added support for PostgreSQL timestamptz columns, enabling proper handling of timezone-aware timestamps.
  • Tests

    • Updated Postgres tests to cover timestamptz handling, enable query caching in test runs, and add runtime assertions verifying Date values and equality.

PR Type

Bug fix, Tests


Description

  • Add support for PostgreSQL timestamptz type in persistence/hydration

  • Include timestamptz in date serialization and deserialization logic

  • Enable query caching in column types test for proper cache validation

  • Add runtime assertions verifying Date instances and value equality


Diagram Walkthrough

flowchart LR
  A["PostgreSQL timestamptz column"] -->|"serialize/deserialize"| B["DateUtils functions"]
  B -->|"mixedDateToDate"| C["Date persistence"]
  B -->|"normalizeHydratedDate"| D["Date hydration"]
  E["Test with cache enabled"] -->|"validates"| C
  E -->|"validates"| D
Loading

File Walkthrough

Relevant files
Bug fix
PostgresDriver.ts
Add timestamptz to date serialization/hydration                   

src/driver/postgres/PostgresDriver.ts

  • Added timestamptz type check in serialization method alongside
    existing timestamp types
  • Added timestamptz type check in hydration method for proper Date
    normalization
  • Ensures timezone-aware timestamps are handled consistently with other
    timestamp variants
+2/-0     
Tests
column-types-postgres.ts
Enable caching and add timestamptz assertions                       

test/functional/database-schema/column-types/postgres/column-types-postgres.ts

  • Added post.timestampTz assignment with Date value in test data setup
  • Enabled query caching with cache: true option in both find operations
  • Added assertions validating timestampTz value equality and Date
    instance type
  • Uncommented and fixed timestampWithTimeZone assertions with proper
    Date type checks
+21/-4   
PostWithOptions.ts
Add timestamptz column to test entity                                       

test/functional/database-schema/column-types/postgres/entity/PostWithOptions.ts

  • Added new @Column("timestamptz") decorated property timestampTz of
    type Date
  • Positioned after existing timestamp columns for logical grouping
+3/-0     

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jan 30, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Remove redundant and confusing database call

Remove the redundant postRepository.findOne call from the test. A single call is
sufficient for testing type hydration and simplifies the code.

test/functional/database-schema/column-types/postgres/column-types-postgres.ts [406-418]

 await postRepository.save(post)
-await postRepository.findOne({
-    where: {
-        id: 1,
-    },
-    cache: true,
-})
+
 const loadedPost = (await postRepository.findOne({
     where: {
         id: 1,
     },
-    cache: true,
 }))!
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a redundant findOne call introduced in the test, which complicates the code and is irrelevant to the test's purpose of verifying column types. Removing it improves test clarity and focus.

Medium
  • More

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Missing timestamptz in withPrecisionColumnTypes array 🐞 Bug ✓ Correctness
Description
• The withPrecisionColumnTypes array in PostgresDriver.ts lists column types that support
  precision, but timestamptz is not included despite being added to other timestamp type checks
• This array is used by the framework to determine which column types can have precision specified,
  and its absence will cause the framework to reject or ignore precision values for timestamptz
  columns
• This creates inconsistent type handling where timestamptz is recognized in some code paths but
  not in precision-related operations, leading to schema validation failures
Code

src/driver/postgres/PostgresDriver.ts[661]

+            columnMetadata.type === "timestamptz" ||
Evidence
The PR adds timestamptz to timestamp type checks at lines 661 and 749 in PostgresDriver.ts, but
the withPrecisionColumnTypes array at lines 226-234 was not updated. This array includes both
'timestamp without time zone' and 'timestamp with time zone', and since timestamptz is
PostgreSQL's alias for 'timestamp with time zone' (as shown by the normalizeType method at line
1012), it should also be in this array. The test entity demonstrates the use case with a
timestamptz column defined without precision options.

src/driver/postgres/PostgresDriver.ts[226-234]
src/driver/postgres/PostgresDriver.ts[1012-1013]
test/functional/database-schema/column-types/postgres/entity/PostWithOptions.ts[46-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue Description
The `withPrecisionColumnTypes` array in PostgresDriver.ts is missing the &#x27;timestamptz&#x27; type, which prevents the framework from recognizing that timestamptz columns can have precision specified. This causes schema validation failures and inconsistent type handling.

## Issue Context
The PR adds `timestamptz` support in timestamp type checks (lines 661, 749) but doesn&#x27;t update the `withPrecisionColumnTypes` array. Since `timestamptz` is PostgreSQL&#x27;s alias for &#x27;timestamp with time zone&#x27; and supports precision (0-6), it should be included in this array alongside the other timestamp types.

## Fix Focus Areas
- src/driver/postgres/PostgresDriver.ts[226-234]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Missing timestamptz in dataTypeDefaults object 🐞 Bug ✓ Correctness
Description
• The dataTypeDefaults object in PostgresDriver.ts specifies default precision values for
  timestamp types but doesn't include timestamptz
• This object is used by BaseQueryRunner to determine if a column's precision is the default value
  (6 for PostgreSQL timestamps)
• Without this entry, the framework cannot correctly identify when a timestamptz column uses
  default precision, causing unnecessary schema synchronization operations and potential data
  integrity issues
Code

src/driver/postgres/PostgresDriver.ts[661]

+            columnMetadata.type === "timestamptz" ||
Evidence
The PR adds timestamptz to timestamp type checks but doesn't update the dataTypeDefaults object
at lines 280-288. This object includes default precision of 6 for both 'timestamp without time zone'
and 'timestamp with time zone'. The BaseQueryRunner uses this object in the
isDefaultColumnPrecision method (lines 610-620) to determine if a column's precision matches the
default. Without the timestamptz entry, precision comparison will fail for timestamptz columns,
causing schema synchronization to incorrectly detect differences.

src/driver/postgres/PostgresDriver.ts[280-288]
src/query-runner/BaseQueryRunner.ts[610-620]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue Description
The `dataTypeDefaults` object in PostgresDriver.ts is missing the &#x27;timestamptz&#x27; type with its default precision value. This prevents the framework from correctly identifying when a timestamptz column uses the default precision, causing schema synchronization issues.

## Issue Context
PostgreSQL&#x27;s `timestamptz` type has a default precision of 6, same as &#x27;timestamp with time zone&#x27;. The BaseQueryRunner&#x27;s `isDefaultColumnPrecision` method relies on this object to determine if a column&#x27;s precision is the default value. Without this entry, the method will always return false for timestamptz columns, triggering unnecessary schema updates.

## Fix Focus Areas
- src/driver/postgres/PostgresDriver.ts[280-288]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Test missing database column type validation 🐞 Bug ⛯ Reliability
Description
• The test adds a new timestampTz column and validates data persistence/hydration but doesn't
  validate the database column type
• All other timestamp columns in the test have assertions checking their database type (e.g.,
  'timestamp without time zone', 'timestamp with time zone'), but timestampTz lacks this validation
• This gap in test coverage means the PR doesn't verify that timestamptz is correctly normalized
  to 'timestamp with time zone' in the database schema, leaving potential type normalization bugs
  undetected
Code

test/functional/database-schema/column-types/postgres/column-types-postgres.ts[402]

+                post.timestampTz = new Date()
Evidence
The test adds a timestampTz column at line 402 and validates data correctness at lines 436-439, but
there's no corresponding schema type validation. In contrast, the timestamp column has type
validation at lines 486-487 checking for 'timestamp without time zone', and timestampWithTimeZone
has validation at lines 492-493 checking for 'timestamp with time zone'. The test should verify that
timestampTz is normalized to 'timestamp with time zone' in the database schema.

test/functional/database-schema/column-types/postgres/column-types-postgres.ts[436-439]
test/functional/database-schema/column-types/postgres/column-types-postgres.ts[486-487]
test/functional/database-schema/column-types/postgres/column-types-postgres.ts[492-493]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue Description
The test validates data persistence and hydration for the timestampTz column but doesn&#x27;t validate that the database column type is correctly set. This leaves a gap in test coverage that could allow type normalization bugs to go undetected.

## Issue Context
The test should verify that when a column is defined as `@Column(&quot;timestamptz&quot;)`, the actual database column type is &#x27;timestamp with time zone&#x27; (since timestamptz is an alias). This validation pattern is already used for other timestamp columns in the test.

## Fix Focus Areas
- test/functional/database-schema/column-types/postgres/column-types-postgres.ts[497-513]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



ⓘ The new review experience is currently in Beta. Learn more

Qodo Logo

columnMetadata.type === "datetime" ||
columnMetadata.type === Date ||
columnMetadata.type === "timestamp" ||
columnMetadata.type === "timestamptz" ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Missing timestamptz in withprecisioncolumntypes array 🐞 Bug ✓ Correctness

• The withPrecisionColumnTypes array in PostgresDriver.ts lists column types that support
  precision, but timestamptz is not included despite being added to other timestamp type checks
• This array is used by the framework to determine which column types can have precision specified,
  and its absence will cause the framework to reject or ignore precision values for timestamptz
  columns
• This creates inconsistent type handling where timestamptz is recognized in some code paths but
  not in precision-related operations, leading to schema validation failures
Agent prompt
## Issue Description
The `withPrecisionColumnTypes` array in PostgresDriver.ts is missing the 'timestamptz' type, which prevents the framework from recognizing that timestamptz columns can have precision specified. This causes schema validation failures and inconsistent type handling.

## Issue Context
The PR adds `timestamptz` support in timestamp type checks (lines 661, 749) but doesn't update the `withPrecisionColumnTypes` array. Since `timestamptz` is PostgreSQL's alias for 'timestamp with time zone' and supports precision (0-6), it should be included in this array alongside the other timestamp types.

## Fix Focus Areas
- src/driver/postgres/PostgresDriver.ts[226-234]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

columnMetadata.type === "datetime" ||
columnMetadata.type === Date ||
columnMetadata.type === "timestamp" ||
columnMetadata.type === "timestamptz" ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Missing timestamptz in datatypedefaults object 🐞 Bug ✓ Correctness

• The dataTypeDefaults object in PostgresDriver.ts specifies default precision values for
  timestamp types but doesn't include timestamptz
• This object is used by BaseQueryRunner to determine if a column's precision is the default value
  (6 for PostgreSQL timestamps)
• Without this entry, the framework cannot correctly identify when a timestamptz column uses
  default precision, causing unnecessary schema synchronization operations and potential data
  integrity issues
Agent prompt
## Issue Description
The `dataTypeDefaults` object in PostgresDriver.ts is missing the 'timestamptz' type with its default precision value. This prevents the framework from correctly identifying when a timestamptz column uses the default precision, causing schema synchronization issues.

## Issue Context
PostgreSQL's `timestamptz` type has a default precision of 6, same as 'timestamp with time zone'. The BaseQueryRunner's `isDefaultColumnPrecision` method relies on this object to determine if a column's precision is the default value. Without this entry, the method will always return false for timestamptz columns, triggering unnecessary schema updates.

## Fix Focus Areas
- src/driver/postgres/PostgresDriver.ts[280-288]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review


ⓘ The new review experience is currently in Beta. Learn more

Qodo Logo

@alumni alumni changed the title fix(postgres): 'timestamptz' type persistence/hydration fix(postgres): handle timestamptz persistence/hydration correctly Jan 30, 2026
@alumni

alumni commented Jan 30, 2026 •

Copy link
Copy Markdown
Collaborator

In Postgres, timestamptz is just an alias for timestamp with time zone. I need to check how PG reports it to avoid constant generation of migrations.

Later edit: Never mind, we already convert it to the actual column type in normalizeType

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 81.125%. remained the same
when pulling f4e0706 on Minishlink:patch-1
into 56137a1 on typeorm:master.

@alumni
alumni merged commit c26fc33 into typeorm:master Jan 30, 2026
38 of 39 checks passed
kranners pushed a commit to kranners/typeorm that referenced this pull request Feb 2, 2026
kranners pushed a commit to kranners/typeorm that referenced this pull request Mar 1, 2026
@pkuczynski pkuczynski added this to the 1.0 milestone Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants