Skip to content

feat(pg-core): add native daterange column type#5613

Open
alexbaileyuk wants to merge 3 commits intodrizzle-team:mainfrom
alexbaileyuk:feat/daterange-column-type
Open

feat(pg-core): add native daterange column type#5613
alexbaileyuk wants to merge 3 commits intodrizzle-team:mainfrom
alexbaileyuk:feat/daterange-column-type

Conversation

@alexbaileyuk
Copy link
Copy Markdown

Summary

Adds first-class support for the PostgreSQL daterange column type, partially addressing #2700.

  • New daterange() column builder with two modes:
    • Object mode (default): parses to PgRange<string> with typed lower/upper bounds, inclusivity flags, and empty range detection
    • String mode: raw PostgreSQL text passthrough
  • Shared range infrastructure (PgRange<T>, parseRange, serializeRange) in range.common.ts, designed for reuse when adding the remaining range/multirange types (int4range, int8range, numrange, tsrange, tstzrange, and their multirange counterparts)
  • drizzle-kit introspection support so daterange columns are correctly recognized during pull

Usage

import { pgTable, serial, daterange } from 'drizzle-orm/pg-core';
import type { PgRange } from 'drizzle-orm/pg-core';

const events = pgTable('events', {
  id: serial('id').primaryKey(),
  period: daterange('period').notNull(),
  periodRaw: daterange('period_raw', { mode: 'string' }),
});

// Insert
const range: PgRange<string> = {
  lower: '2025-01-01',
  upper: '2025-12-31',
  lowerInc: true,
  upperInc: false,
  empty: false,
};
await db.insert(events).values({ period: range });

Test plan

  • All 6 new integration tests pass (normal ranges, string mode, empty ranges, unbounded ranges, nullable columns, raw SQL)
  • All 13 existing drizzle-kit pg-columns tests pass (no regressions)
  • drizzle-orm type-checks cleanly
  • Verify drizzle-kit push + pull round-trip with a live PG database

🤖 Generated with Claude Code

alexbaileyuk and others added 3 commits April 8, 2026 11:04
Adds first-class support for the PostgreSQL `daterange` column type,
addressing part of drizzle-team#2700. Includes shared range parsing infrastructure
(PgRange<T>, parseRange, serializeRange) designed for reuse when adding
the remaining range/multirange types.

Supports two modes:
- Object mode (default): parses to PgRange<string> with lower/upper
  bounds, inclusivity flags, and empty detection
- String mode: passes raw PG text through unchanged

Also adds drizzle-kit introspection support so `daterange` columns are
correctly recognized during `pull`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace loose toBeTruthy() checks with exact toEqual() assertions
where PG canonicalization doesn't alter the output (upper bound
already exclusive).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alexbaileyuk alexbaileyuk marked this pull request as ready for review April 8, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant