{"id":"ac0f08b28b57a1a7","repo":"sequelize/sequelize","slug":"this-getdatatypeid-received-an-integer-util","errorCode":null,"errorMessage":"${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.","messagePattern":"(.+?) received an integer (.+?) that is not a safely represented using the JavaScript number type\\. Use a JavaScript bigint or a string instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/abstract-dialect/data-types.ts","lineNumber":1270,"sourceCode":"    if (!this.isUnconstrained() && !decimalSupport.constrained) {\n      dialect.warnDataTypeIssue(\n        `${dialect.name} does not support constrained DECIMAL types. The \"precision\" and \"scale\" options will be ignored.`,\n      );\n      this.options.scale = undefined;\n      this.options.precision = undefined;\n    }\n  }\n\n  sanitize(value: AcceptedNumber): AcceptedNumber {\n    if (typeof value === 'number') {\n      // Some dialects support NaN\n      if (Number.isNaN(value)) {\n        return value;\n      }\n\n      // catch loss of precision issues\n      if (Number.isInteger(value) && !Number.isSafeInteger(value)) {\n        throw new Error(\n          `${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.`,\n        );\n      }\n    }\n\n    // Decimal is arbitrary precision, and *must* be represented as strings, as the JS number type does not support arbitrary precision.\n    return String(value);\n  }\n\n  protected _supportsNativeUnsigned(_dialect: AbstractDialect): boolean {\n    const decimalSupport = _dialect.supports.dataTypes.DECIMAL;\n\n    return decimalSupport && decimalSupport.unsigned;\n  }\n\n  protected getNumberSqlTypeName(): string {\n    return 'DECIMAL';\n  }","sourceCodeStart":1252,"sourceCodeEnd":1288,"githubUrl":"https://github.com/sequelize/sequelize/blob/7e1deec499d5afbb8d1877c2f4d545cead1214ec/packages/core/src/abstract-dialect/data-types.ts#L1252-L1288","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait Account.create({ balance: 9007199254740993 }); // unsafe integer\n\n// after\nawait Account.create({ balance: '9007199254740993' });\n// or\nawait Account.create({ balance: 9007199254740993n });","handlingStrategy":"type-guard","validationCode":"function toDecimalValue(v) {\n  if (typeof v === 'number' && Number.isInteger(v) && !Number.isSafeInteger(v)) {\n    throw new Error(`Unsafe integer ${v}; pass as string or bigint`);\n  }\n  return typeof v === 'number' && !Number.isSafeInteger(v) ? String(v) : v;\n}","typeGuard":"function isSafeDecimalInput(v) {\n  if (typeof v !== 'number') return true;\n  return !Number.isInteger(v) || Number.isSafeInteger(v);\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["data-types","decimal","precision-loss","bigint","safe-integer"],"analyzedSha":"7e1deec499d5afbb8d1877c2f4d545cead1214ec","analyzedAt":"2026-08-03T18:58:44.549Z","schemaVersion":2}