{"record":{"id":"96bb946f1ba5c285","repo":"NationalSecurityAgency/ghidra","slug":"did-not-get-result-code-after-deletion","errorCode":null,"errorMessage":"Did not get result code after deletion","messagePattern":"Did not get result code after deletion","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/PostgresFunctionDatabase.java","lineNumber":434,"sourceCode":"\t}\n\n\t/**\n\t * Low level count decrement of a vector record from vectable, if count\n\t * reaches zero, the record is deleted\n\t * @param id vector row ID\n\t * @param countdiff the amount to subtract from count\n\t * @return 0 if decrement short of 0, return 1 if record was removed, return\n\t *         -1 if there was a problem\n\t * @throws SQLException if there is a problem creating or executing the query\n\t */\n\t@Override\n\tprotected int deleteVectors(long id, int countdiff) throws SQLException {\n\t\tint res = -100;\n\t\tString sql =\n\t\t\t\"SELECT remove_vec( \" + Long.toString(id) + ',' + Integer.toString(countdiff) + \")\";\n\t\ttry (ResultSet rs = getReusableStatement().executeQuery(sql)) {\n\t\t\tif (!rs.next()) {\n\t\t\t\tthrow new SQLException(\"Did not get result code after deletion\");\n\t\t\t}\n\t\t\tres = rs.getInt(1);\n\t\t}\n\t\treturn res;\n\t}\n\n\t/**\n\t * \n\t * @param resultset the list of result set objects to populate\n\t * @param vec the vector containing the saveSQL query statement\n\t * @param simthresh the similarity threshold\n\t * @param sigthresh the confidence threshold\n\t * @param max the max number of results to return\n\t * @return the number of results returned\n\t * @throws SQLException if there is a problem creating or executing the query\n\t */\n\t@Override\n\tprotected int queryNearestVector(List<VectorResult> resultset, LSHVector vec, double simthresh,","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/PostgresFunctionDatabase.java#L416-L452","documentation":"Thrown by PostgresFunctionDatabase.deleteVectors() when the remove_vec() stored function returns a ResultSet with no rows. Normally remove_vec returns an integer status code (0 = decremented, 1 = removed, -1 = problem); an empty result set means the function did not return the expected scalar.","triggerScenarios":"Calling deleteVectors(id, countdiff) and the SQL \"SELECT remove_vec(...)\" returns zero rows. This indicates the remove_vec stored function is missing, corrupted, or not behaving as expected — analogous to the insert_vec case but for vector deletion.","commonSituations":"The lshvector extension is corrupted or missing the remove_vec function. A version mismatch between the extension and client. The database was partially restored leaving stored functions inconsistent.","solutions":["Verify the lshvector extension is intact and remove_vec returns a scalar integer.","Reinstall or recreate the extension if the function is missing.","Check extension/client version compatibility.","Ensure the vector id and countdiff parameters are valid (id exists in vectable)."],"exampleFix":"// before\nint res = db.deleteVectors(id, countdiff); // throws \"Did not get result code after deletion\"\n\n// after — verify the stored function exists and works\n// psql: SELECT remove_vec(1, 1); -- should return an int\n// reinstall extension if it returns nothing, then retry","handlingStrategy":"validation","validationCode":"// Verify the remove_vec function exists\ntry (Connection c = dataSource.getConnection();\n     Statement st = c.createStatement();\n     ResultSet rs = st.executeQuery(\n         \"SELECT proname FROM pg_proc WHERE proname = 'remove_vec'\")) {\n    if (!rs.next()) {\n        throw new IllegalStateException(\"remove_vec function missing; reinstall extension\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    int res = db.deleteVectors(id, countdiff);\n} catch (SQLException e) {\n    if (e.getMessage().contains(\"Did not get result code\")) {\n        // extension function issue; verify and reinstall if needed\n        throw e;\n    }\n    throw e;\n}","preventionTips":["Verify lshvector extension integrity (including remove_vec) before deletion operations.","Ensure the vector id exists in vectable before attempting to decrement.","Keep extension and client versions aligned."],"tags":["bsim","ghidra","postgresql","database","stored-function","extension"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}