sequelize/sequelize · error · Error
${this.getDataTypeId()} received an integer ${util.inspect(v
Error message
${this.getDataTypeId()} received an integer ${util.inspect(value)} that is not a safely represented using the JavaScript number type. Use a JavaScript bigint or a string instead. What it means
DECIMAL.sanitize (data-types.ts:1269) refuses integer numbers that exceed Number.MAX_SAFE_INTEGER (i.e. Number.isInteger(value) && !Number.isSafeInteger(value)). DECIMAL is arbitrary-precision and must be stringified (see line 1277), so feeding an unsafe JS integer would silently corrupt the value. The library instead asks for a bigint or a string so the full precision is preserved.
Source
Thrown at packages/core/src/abstract-dialect/data-types.ts:1270
if (!this.isUnconstrained() && !decimalSupport.constrained) {
dialect.warnDataTypeIssue(
`${dialect.name} does not support constrained DECIMAL types. The "precision" and "scale" options will be ignored.`,
);
this.options.scale = undefined;
this.options.precision = undefined;
}
}
sanitize(value: AcceptedNumber): AcceptedNumber {
if (typeof value === 'number') {
// Some dialects support NaN
if (Number.isNaN(value)) {
return value;
}
// catch loss of precision issues
if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
throw new Error(
`${this.getDataTypeId()} received an integer ${util.inspect(value)} that is not a safely represented using the JavaScript number type. Use a JavaScript bigint or a string instead.`,
);
}
}
// Decimal is arbitrary precision, and *must* be represented as strings, as the JS number type does not support arbitrary precision.
return String(value);
}
protected _supportsNativeUnsigned(_dialect: AbstractDialect): boolean {
const decimalSupport = _dialect.supports.dataTypes.DECIMAL;
return decimalSupport && decimalSupport.unsigned;
}
protected getNumberSqlTypeName(): string {
return 'DECIMAL';
}View on GitHub (pinned to 7e1deec499)
Solutions
- Pass the value as a string: await Model.create({ amount: '9007199254740993' }).
- Pass a JS bigint: { amount: 9007199254740993n } (ensure your driver/dialect accepts bigint binding).
- If the value originates from JSON, parse with a reviver or use a lossless JSON parser so large integers stay strings.
- Avoid arithmetic that produces unsafe integers; cap values client-side.
Example fix
// before
await Account.create({ balance: 9007199254740993 }); // unsafe integer
// after
await Account.create({ balance: '9007199254740993' });
// or
await Account.create({ balance: 9007199254740993n }); Defensive patterns
Strategy: type-guard
Validate before calling
function toDecimalValue(v) {
if (typeof v === 'number' && Number.isInteger(v) && !Number.isSafeInteger(v)) {
throw new Error(`Unsafe integer ${v}; pass as string or bigint`);
}
return typeof v === 'number' && !Number.isSafeInteger(v) ? String(v) : v;
} Type guard
function isSafeDecimalInput(v) {
if (typeof v !== 'number') return true;
return !Number.isInteger(v) || Number.isSafeInteger(v);
} Prevention
- Store large numeric IDs as strings end-to-end.
- Parse JSON containing big integers with a lossless parser or a reviver.
- Never perform arithmetic that can produce integers beyond 2^53 for DECIMAL columns.
When it happens
Trigger: Inserting a JavaScript number like 9007199254740993 (2^53+1) or a large numeric ID parsed from JSON as a number into a DECIMAL column; receiving a large integer from an external API as a plain number and saving it directly.
Common situations: Storing large 64-bit numeric IDs (Snowflake, BigInt PKs) in DECIMAL; JSON.parse turning a big integer into an unsafe number before insert; aggregations or computations producing integers beyond MAX_SAFE_INTEGER.
Related errors
- The ${this.getDataTypeId()} DataType requires that the "prec
- The ${this.getDataTypeId()} DataType requires that the "scal
- ${dialect.name} does not support unconstrained DECIMAL types
- Expected type to be a string, a DataType class, or a DataTyp
- Validation encountered an unexpected error while validating
AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03).
Data as JSON: /data/errors/ac0f08b28b57a1a7.json.
Report an issue: GitHub.