{"record":{"id":"eeb50b7582068812","repo":"micro/go-micro","slug":"unsupported-statement","errorCode":null,"errorMessage":"unsupported statement","messagePattern":"unsupported statement","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store/postgres/postgres.go","lineNumber":253,"sourceCode":"\n\tif s.dbConn != nil {\n\t\ts.dbConn.Close()\n\t}\n\n\t// save the values\n\ts.dbConn = db\n\n\t// get DB\n\tdatabase, table := s.getDB(s.options.Database, s.options.Table)\n\n\t// initialize the database\n\treturn s.initDB(database, table)\n}\n\nfunc (s *sqlStore) prepare(database, table, query string) (*sql.Stmt, error) {\n\tst, ok := statements[query]\n\tif !ok {\n\t\treturn nil, errors.New(\"unsupported statement\")\n\t}\n\n\t// get DB\n\tdatabase, table = s.getDB(database, table)\n\n\tq := fmt.Sprintf(st, database, table)\n\n\tdb, err := s.db()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tstmt, err := db.Prepare(q)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn stmt, nil\n}\n","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/store/postgres/postgres.go#L235-L271","documentation":"prepare() looks up the requested query string in a fixed map of prebuilt SQL statements. If the query key is not one of the statements the postgres store prepared at init time, it returns 'unsupported statement'. It is an internal invariant check: callers (List, Read, read, Write, Delete) should only ever pass known keys, so this error almost always means an internal mismatch or an unprepared custom query.","triggerScenarios":"Any of sqlStore.Read/read/Write/Delete/List passing a query key absent from the statements map — e.g. after a code change adds a new query without registering it in statements, or a customized/forked build where statement keys were renamed.","commonSituations":"Hitting this after upgrading the library where internal query names changed; running a patched store with custom SQL that was never added to statements; namespace/database code paths (prefix/suffix reads) that reference a statement not prepared for the current table layout.","solutions":["Check which operation was called and confirm the query key it passes exists in the statements map in store/postgres/postgres.go","If you patched the store, register your custom SQL in the statements map so prepare() can find it","If it came from an upgrade, pin the version that matches your code or update any forked statement keys to the new names"],"exampleFix":"// before\nstatements[\"read.prefix\"] = \"SELECT ...\" // used in read() but never referenced\n// after\nstatements[\"read.prefix\"] = \"SELECT ...\"\n// and ensure read() calls s.prepare(database, table, \"read.prefix\") with the exact same key","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, err := s.prepare(db, tbl, q); err != nil && err.Error() == \"unsupported statement\" {\n\t// log offending query key q and fall back or fail fast\n}","preventionTips":["Keep query keys centralized as constants shared by statements map and callers","Add a startup self-test that prepares every registered statement","After upgrades, run the store integration tests to catch renamed statement keys"],"tags":["postgres","store","sql","internal"],"backgroundTag":"unsupported-statement","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}