{"id":"4f32b8a8e78375df","repo":"jackc/pgx","slug":"failed-to-deallocate-previously-failed-statement","errorCode":null,"errorMessage":"failed to deallocate previously failed statement %q: %w","messagePattern":"failed to deallocate previously failed statement %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"conn.go","lineNumber":324,"sourceCode":"\n\terr := c.pgConn.Close(ctx)\n\treturn err\n}\n\n// Prepare creates a prepared statement with name and sql. sql can contain placeholders for bound parameters. These\n// placeholders are referenced positionally as $1, $2, etc. name can be used instead of sql with [Conn.Query],\n// [Conn.QueryRow], and [Conn.Exec] to execute the statement. It can also be used with [Batch.Queue].\n//\n// The underlying PostgreSQL identifier for the prepared statement will be name if name != sql or a digest of sql if\n// name == sql.\n//\n// Prepare is idempotent; i.e. it is safe to call Prepare multiple times with the same name and sql arguments. This\n// allows a code path to Prepare and Query/Exec without concern for if the statement has already been prepared.\nfunc (c *Conn) Prepare(ctx context.Context, name, sql string) (sd *pgconn.StatementDescription, err error) {\n\tif c.failedDescribeStatement != \"\" {\n\t\terr = c.Deallocate(ctx, c.failedDescribeStatement)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to deallocate previously failed statement %q: %w\", c.failedDescribeStatement, err)\n\t\t}\n\t\tc.failedDescribeStatement = \"\"\n\t}\n\n\tif c.prepareTracer != nil {\n\t\tctx = c.prepareTracer.TracePrepareStart(ctx, c, TracePrepareStartData{Name: name, SQL: sql})\n\t}\n\n\tif name != \"\" {\n\t\tvar ok bool\n\t\tif sd, ok = c.preparedStatements[name]; ok && sd.SQL == sql {\n\t\t\tif c.prepareTracer != nil {\n\t\t\t\tc.prepareTracer.TracePrepareEnd(ctx, c, TracePrepareEndData{AlreadyPrepared: true})\n\t\t\t}\n\t\t\treturn sd, nil\n\t\t}\n\t}\n","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/conn.go#L306-L342","documentation":"Error \"failed to deallocate previously failed statement %q: %w\" thrown in jackc/pgx.","triggerScenarios":"Thrown at conn.go:324 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}