{"record":{"id":"078b11b8be9e7d8a","repo":"jackc/pgx","slug":"d-is-less-than-minimum-value-for-int2-078b11","errorCode":null,"errorMessage":"%d is less than minimum value for Int2","messagePattern":"(.+?) is less than minimum value for Int2","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/zeronull/int.go","lineNumber":26,"sourceCode":"\t\"math\"\n\n\t\"github.com/jackc/pgx/v5/pgtype\"\n)\n\ntype Int2 int16\n\n// SkipUnderlyingTypePlan implements the [pgtype.SkipUnderlyingTypePlanner] interface.\nfunc (Int2) SkipUnderlyingTypePlan() {}\n\n// ScanInt64 implements the [pgtype.Int64Scanner] interface.\nfunc (dst *Int2) ScanInt64(n pgtype.Int8) error {\n\tif !n.Valid {\n\t\t*dst = 0\n\t\treturn nil\n\t}\n\n\tif n.Int64 < math.MinInt16 {\n\t\treturn fmt.Errorf(\"%d is less than minimum value for Int2\", n.Int64)\n\t}\n\tif n.Int64 > math.MaxInt16 {\n\t\treturn fmt.Errorf(\"%d is greater than maximum value for Int2\", n.Int64)\n\t}\n\t*dst = Int2(n.Int64)\n\n\treturn nil\n}\n\n// Int64Value implements the [pgtype.Int64Valuer] interface.\nfunc (src Int2) Int64Value() (pgtype.Int8, error) {\n\tif src == 0 {\n\t\treturn pgtype.Int8{}, nil\n\t}\n\treturn pgtype.Int8{Int64: int64(src), Valid: true}, nil\n}\n\n// Scan implements the [database/sql.Scanner] interface.","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/zeronull/int.go#L8-L44","documentation":"ScanInt64 on zero-null Int2 fires when the incoming int64 is below math.MinInt16 and would silently wrap if stored in the int16-based type. The input at fault is the database value, which falls outside the range the Go type (and PostgreSQL smallint) can represent.","triggerScenarios":"Thrown at pgtype/zeronull/int.go:26 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Switch the Go type to zero-null Int4/Int8 or plain int64 to match the column's real range","Alter the column to integer or bigint","Clamp or reject out-of-range values in the query or with a CHECK constraint"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}