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

  1. Pass the value as a string: await Model.create({ amount: '9007199254740993' }).
  2. Pass a JS bigint: { amount: 9007199254740993n } (ensure your driver/dialect accepts bigint binding).
  3. If the value originates from JSON, parse with a reviver or use a lossless JSON parser so large integers stay strings.
  4. 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

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


AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03). Data as JSON: /data/errors/ac0f08b28b57a1a7.json. Report an issue: GitHub.