rqlite/rqlite · warning
query not specified
Error message
query not specified
What it means
Raised by the /db/analyze handler when the request is a GET and the `q` (query) URL parameter is empty or absent. The analyze endpoint needs at least one SQL statement to inspect, so the request is rejected with 400 before any parsing happens.
Source
Thrown at http/service.go:604
// handleSQLAnalyze handles requests to analyze and show SQL rewriting.
func (s *Service) handleSQLAnalyze(w http.ResponseWriter, r *http.Request, qp QueryParams) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
if !s.CheckRequestPerm(r, auth.PermQuery) {
w.WriteHeader(http.StatusUnauthorized)
return
}
if r.Method != "GET" && r.Method != "POST" {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
var stmts []*proto.Statement
if r.Method == "GET" {
q := qp.Query()
if q == "" {
http.Error(w, "query not specified", http.StatusBadRequest)
return
}
stmts = []*proto.Statement{{Sql: q}}
} else {
var err error
stmts, err = ParseRequest(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
}
analyzeStmt := func(sqlStr string, rwRand, rwTime bool) (res sqlAnalyzeStmtResult, retErr error) {
defer func() {
if r := recover(); r != nil {
retErr = fmt.Errorf("panic during SQL analysis: %v", r)
}
}()View on GitHub (pinned to 7586a4d1bd)
Solutions
- Append the SQL to analyze as the q parameter: GET /db/analyze?q=SELECT+RANDOM().
- URL-encode the SQL statement in the q parameter.
- Alternatively use POST with a JSON body containing the statements array.
Example fix
// before curl 'http://localhost:4001/db/analyze' // 400: query not specified // after curl 'http://localhost:4001/db/analyze?q=SELECT%20RANDOM()'
Defensive patterns
Strategy: validation
Validate before calling
// JS: validate before calling
if (!q || !q.trim()) throw new Error('q query parameter is required for /db/analyze');
const url = `http://host:4001/db/analyze?q=${encodeURIComponent(q)}`; Type guard
function hasQuery(q) { return typeof q === 'string' && q.trim().length > 0 } Try / catch
const res = await fetch(url)
if (res.status === 400 && (await res.text()).includes('query not specified')) {
console.error('Supply ?q=<sql> to /db/analyze')
} Prevention
- Always build /db/analyze URLs through a helper that encodes and appends q.
- Assert q is non-empty in unit tests for client code paths.
- Prefer POST with a JSON statements body for programmatic use to avoid URL param pitfalls.
When it happens
Trigger: GET /db/analyze without `?q=SELECT...`, or with `?q=` empty, or with the SQL supplied in a POST-style body while still issuing a GET request.
Common situations: Copy-pasting the endpoint URL without appending the q parameter; URL-encoding issues dropping the parameter; tools that strip empty query params; confusing /db/analyze (needs q) with /db/query behaviors.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- ErrQueryWrite
- err.Error()
- invalid JSON: %s
- text || ("HTTP " + resp.status)
- boot failed, status code: %s[, body]
AI-assisted analysis of rqlite/rqlite@7586a4d1bd (2026-09-03).
Data as JSON: /api/errors/248dd6be917c1159.
Report an issue: GitHub.