micro/go-micro · error

unsupported statement

Error message

unsupported statement

What it means

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.

Source

Thrown at store/postgres/postgres.go:253

	if s.dbConn != nil {
		s.dbConn.Close()
	}

	// save the values
	s.dbConn = db

	// get DB
	database, table := s.getDB(s.options.Database, s.options.Table)

	// initialize the database
	return s.initDB(database, table)
}

func (s *sqlStore) prepare(database, table, query string) (*sql.Stmt, error) {
	st, ok := statements[query]
	if !ok {
		return nil, errors.New("unsupported statement")
	}

	// get DB
	database, table = s.getDB(database, table)

	q := fmt.Sprintf(st, database, table)

	db, err := s.db()
	if err != nil {
		return nil, err
	}
	stmt, err := db.Prepare(q)
	if err != nil {
		return nil, err
	}
	return stmt, nil
}

View on GitHub (pinned to 24529f1404)

Solutions

  1. Check which operation was called and confirm the query key it passes exists in the statements map in store/postgres/postgres.go
  2. If you patched the store, register your custom SQL in the statements map so prepare() can find it
  3. If it came from an upgrade, pin the version that matches your code or update any forked statement keys to the new names

Example fix

// before
statements["read.prefix"] = "SELECT ..." // used in read() but never referenced
// after
statements["read.prefix"] = "SELECT ..."
// and ensure read() calls s.prepare(database, table, "read.prefix") with the exact same key
Defensive patterns

Strategy: try-catch

Try / catch

if _, err := s.prepare(db, tbl, q); err != nil && err.Error() == "unsupported statement" {
	// log offending query key q and fall back or fail fast
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01). Data as JSON: /api/errors/eeb50b7582068812. Report an issue: GitHub.