drizzle-team/drizzle-orm · error · RangeError
count exceeds max number of unique intervals(${maxUniqueInte
Error message
count exceeds max number of unique intervals(${maxUniqueIntervalsNumber}) What it means
GenerateIntervalV2 (the unique interval generator) computes the total number of distinct date/time intervals from the product of each field's range (from-to+1) across the selected fields. If the requested count exceeds this product, there are not enough unique interval combinations and init() throws a RangeError.
Source
Thrown at drizzle-seed/src/services/versioning/v2.ts:78
let fieldsToGenerate: string[] = allFields;
if (this.params.fields !== undefined && this.params.fields?.includes(' to ')) {
const tokens = this.params.fields.split(' to ');
const endIdx = allFields.indexOf(tokens[1]!);
fieldsToGenerate = allFields.slice(0, endIdx + 1);
} else if (this.params.fields !== undefined) {
const endIdx = allFields.indexOf(this.params.fields);
fieldsToGenerate = allFields.slice(0, endIdx + 1);
}
let maxUniqueIntervalsNumber = 1;
for (const field of fieldsToGenerate) {
const from = this.config[field]!.from, to = this.config[field]!.to;
maxUniqueIntervalsNumber *= from - to + 1;
}
if (count > maxUniqueIntervalsNumber) {
throw new RangeError(`count exceeds max number of unique intervals(${maxUniqueIntervalsNumber})`);
}
const rng = prand.xoroshiro128plus(seed);
const intervalSet = new Set<string>();
this.state = { rng, fieldsToGenerate, intervalSet };
}
generate() {
if (this.state === undefined) {
throw new Error('state is not defined.');
}
let interval, numb: number;
for (;;) {
interval = '';
for (const field of this.state.fieldsToGenerate) {View on GitHub (pinned to b7862528fd)
Solutions
- Reduce count to at or below the maxUniqueIntervalsNumber printed in the error.
- Expand the fields param to include more date/time components (e.g. 'year to second') to increase the combinatorial space.
- Remove the unique constraint if uniqueness is not required.
Example fix
// before — count 100 but only 'minute' field (max 60 unique)
refinements = { myTable: { columns: { interval: { generator: generators.interval({ fields: 'minute', isUnique: true }) } } } };
await seed(db, { schema }, { count: 100 });
// after — expand fields or reduce count
fields: 'year to minute', // vastly larger space
// or count: 50 Defensive patterns
Strategy: validation
Validate before calling
// Estimate max unique intervals from field ranges before seeding.
// config: year(1970-2030=61) * month(12) * day(31) * hour(24) * minute(60) * second(60)
const FIELD_RANGES: Record<string, number> = { year: 61, month: 12, day: 31, hour: 24, minute: 60, second: 60 };
function maxUniqueIntervals(fields: string[]): number {
return fields.reduce((acc, f) => acc * (FIELD_RANGES[f] ?? 1), 1);
}
// fields 'year to second' => ['year','month','day','hour','minute','second']
function parseFields(param: string): string[] {
const all = ['year','month','day','hour','minute','second'];
if (param.includes(' to ')) {
const tokens = param.split(' to ');
return all.slice(0, all.indexOf(tokens[1]!) + 1);
}
return all.slice(0, all.indexOf(param) + 1);
}
// Usage: if (count > maxUniqueIntervals(parseFields(fields))) reduce count or expand fields. Prevention
- Use a broad fields range ('year to second') for high-count unique interval seeding.
- Keep count within the combinatorial space of the selected fields.
- Drop the unique constraint if interval uniqueness is not essential.
When it happens
Trigger: Requesting a high count on a unique interval column while restricting the fields param to a narrow range (e.g. only 'minute' gives 60 unique values).
Common situations: Seeding a large number of rows with unique interval values; limiting the fields param to a small subset (e.g. 'second' only) which caps the combinatorial space at 60.
Related errors
- count exceeds max number of unique company names(${maxUnique
- You can't generate ${count} unique strings, with a maximum s
- Table '${tableGen.tableName}' does not have primary or (uniq
AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03).
Data as JSON: /data/errors/15e58d2dab363053.json.
Report an issue: GitHub.