{"record":{"id":"c63974eba329a66b","repo":"NationalSecurityAgency/ghidra","slug":"did-not-get-vector-id-after-insertion","errorCode":null,"errorMessage":"Did not get vector id after insertion","messagePattern":"Did not get vector id after insertion","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/PostgresFunctionDatabase.java","lineNumber":412,"sourceCode":"\t\t\t}\n\t\t\tst.execute(\"DROP EXTENSION pg_prewarm\");\n\n\t\t\treturn res;\n\t\t}\n\t}\n\n\t/**\n\t * Make sure the vector corresponding to the SignatureRecord is inserted into the vectable\n\t * @param sigrec is the SignatureRecord\n\t * @return the computed id of the vector\n\t * @throws SQLException if there is a problem creating or executing the query\n\t */\n\t@Override\n\tprotected long storeSignatureRecord(SignatureRecord sigrec) throws SQLException {\n\t\tString sql = \"SELECT insert_vec( '\" + sigrec.getLSHVector().saveSQL() + \"')\";\n\t\ttry (ResultSet rs = getReusableStatement().executeQuery(sql)) {\n\t\t\tif (!rs.next()) {\n\t\t\t\tthrow new SQLException(\"Did not get vector id after insertion\");\n\t\t\t}\n\t\t\treturn rs.getLong(1);\n\t\t}\n\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 =","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/PostgresFunctionDatabase.java#L394-L430","documentation":"Thrown by PostgresFunctionDatabase.storeSignatureRecord() when the insert_vec() stored function returns a ResultSet with no rows. Normally insert_vec() returns the newly assigned vector row id; an empty result set indicates the stored function did not execute as expected or returned no data.","triggerScenarios":"Calling storeSignatureRecord(sigrec) and the SQL \"SELECT insert_vec(...)\" returns zero rows. This can happen if the lshvector extension's insert_vec function is missing or corrupted, returns void/nothing instead of a scalar, or the vector's saveSQL() output is invalid causing the function to silently fail.","commonSituations":"The PostgreSQL lshvector extension was not properly installed or was corrupted. A version mismatch between the extension and the BSim client. The LSHVector.saveSQL() produced malformed SQL that the function could not parse. A database restore left stored functions in an inconsistent state.","solutions":["Verify the lshvector extension is installed and its insert_vec function returns a scalar bigint.","Check the BSim extension version matches the client version.","Inspect the generated SQL (sigrec.getLSHVector().saveSQL()) for malformed output.","Recreate the database if the extension functions are in an inconsistent state."],"exampleFix":"// before — insert_vec returns no rows due to corrupted extension\nlong vecId = db.storeSignatureRecord(sigrec); // throws\n\n// after — verify extension on the server\n// psql: SELECT proname, prorettype FROM pg_proc WHERE proname = 'insert_vec';\n// reinstall extension if missing, then retry","handlingStrategy":"validation","validationCode":"// Verify the insert_vec function exists and returns a scalar\ntry (Connection c = dataSource.getConnection();\n     Statement st = c.createStatement();\n     ResultSet rs = st.executeQuery(\n         \"SELECT proname FROM pg_proc WHERE proname = 'insert_vec'\")) {\n    if (!rs.next()) {\n        throw new IllegalStateException(\"insert_vec function missing; reinstall lshvector extension\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    long vecId = db.storeSignatureRecord(sigrec);\n} catch (SQLException e) {\n    if (e.getMessage().contains(\"Did not get vector id\")) {\n        // extension issue; verify lshvector functions and version, then retry\n        throw e;\n    }\n    throw e;\n}","preventionTips":["Install and verify the lshvector extension before ingesting signatures.","Ensure extension version matches the BSim client version.","Validate that LSHVector.saveSQL() produces well-formed SQL."],"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"}