Skip to content

[BUG]: [1.0.0-rc.2] [pg] db.select({ maxTimestamp: max(table.timestamp) }).from(table) returns a string value (mode: 'date') #5724

@mdoi2

Description

@mdoi2

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

1.0.0-rc.2

What version of drizzle-kit are you using?

1.0.0-rc.2

Other packages

pg@8.20.0

Describe the Bug

When using 1.0.0-rc.2 + pg to perform aggregations on a timestamp column with mode: ‘date’ using type-safe functions, the result is returned as a string. (The TypeScript type is Date)

Minimal reproduction

import { defineRelations, max } from 'drizzle-orm';
import { drizzle } from 'drizzle-orm/node-postgres';
import { pgTable, serial, timestamp } from 'drizzle-orm/pg-core';
import { expectTypeOf } from 'vitest';

const table = pgTable('table', {
  id: serial().primaryKey().notNull(),
  timestamp: timestamp({ mode: 'date', withTimezone: true }),
});

const db = drizzle({
  connection: process.env.DATABASE_URL,
  relations: defineRelations({ table }),
});

await db.insert(table).values([
  { timestamp: new Date('2026-04-01T00:00Z') },
  { timestamp: null },
]);

const [record] = await db
  .select({
    maxTimestamp: max(table.timestamp),
  })
  .from(table);

expectTypeOf(record?.maxTimestamp).toEqualTypeOf<Date | null | undefined>; // OK
console.log(typeof record?.maxTimestamp); // string

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions