{"id":"df583b98b6a78ce0","repo":"jackc/pgx","slug":"first-sql-argument-must-be-0","errorCode":null,"errorMessage":"first sql argument must be > 0","messagePattern":"first sql argument must be > 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sanitize/sanitize.go","lineNumber":58,"sourceCode":"\t},\n}\n\nvar null = []byte(\"null\")\n\nfunc (q *Query) Sanitize(args ...any) (string, error) {\n\targUse := make([]bool, len(args))\n\tbuf := bufPool.get()\n\tdefer bufPool.put(buf)\n\n\tfor _, part := range q.Parts {\n\t\tswitch part := part.(type) {\n\t\tcase string:\n\t\t\tbuf.WriteString(part)\n\t\tcase int:\n\t\t\targIdx := part - 1\n\t\t\tvar p []byte\n\t\t\tif argIdx < 0 {\n\t\t\t\treturn \"\", fmt.Errorf(\"first sql argument must be > 0\")\n\t\t\t}\n\n\t\t\tif argIdx >= len(args) {\n\t\t\t\treturn \"\", fmt.Errorf(\"insufficient arguments\")\n\t\t\t}\n\n\t\t\t// Prevent SQL injection via Line Comment Creation\n\t\t\t// https://github.com/jackc/pgx/security/advisories/GHSA-m7wr-2xf7-cm9p\n\t\t\tbuf.WriteByte(' ')\n\n\t\t\targ := args[argIdx]\n\t\t\tswitch arg := arg.(type) {\n\t\t\tcase nil:\n\t\t\t\tp = null\n\t\t\tcase int64:\n\t\t\t\tp = strconv.AppendInt(buf.AvailableBuffer(), arg, 10)\n\t\t\tcase float64:\n\t\t\t\tp = strconv.AppendFloat(buf.AvailableBuffer(), arg, 'f', -1, 64)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/internal/sanitize/sanitize.go#L40-L76","documentation":"Error \"first sql argument must be > 0\" thrown in jackc/pgx.","triggerScenarios":"Thrown at internal/sanitize/sanitize.go:58 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}