{"record":{"id":"a46e5cf585fe103a","repo":"influxdata/influxdb","slug":"must-specify-a-db-parameter-or-provide-the-database-in-the","errorCode":null,"errorMessage":"must specify a 'db' parameter, or provide the database in the InfluxQL query","messagePattern":"must specify a 'db' parameter, or provide the database in the InfluxQL query","errorType":"validation","errorClass":"Error::InfluxqlNoDatabase","httpStatus":null,"severity":"error","filePath":"core/iox_v1_query_api/src/error.rs","lineNumber":58,"sourceCode":"\n    /// Serde decode error\n    #[error(\"error decoding params from url: {0}\")]\n    SerdeUrlDecoding(#[from] serde_urlencoded::de::Error),\n\n    // SerdeJsonError\n    #[error(\"error decoding query body: {0}\")]\n    SerdeJson(#[from] serde_json::Error),\n\n    #[error(\"datafusion error: {0}\")]\n    Datafusion(#[from] DataFusionError),\n\n    #[error(\"error in InfluxQL statement: {0}\")]\n    InfluxqlRewrite(#[from] rewrite::Error),\n\n    #[error(\"must provide only one InfluxQl statement per query\")]\n    InfluxqlSingleStatement,\n\n    #[error(\"must specify a 'db' parameter, or provide the database in the InfluxQL query\")]\n    InfluxqlNoDatabase,\n\n    #[error(\n        \"provided a database in both the parameters ({param_db}) and \\\n        query string ({query_db}) that do not match, if providing a query \\\n        that specifies the database, you can omit the 'database' parameter \\\n        from your request\"\n    )]\n    InfluxqlDatabaseMismatch { param_db: String, query_db: String },\n\n    #[error(\n        \"provided a retention policy in both the parameters ({param_rp}) and \\\n        query string ({query_rp}) that do not match, if providing a query \\\n        that specifies the retention_policy, you can omit the 'rp' parameter \\\n        from your request\"\n    )]\n    InfluxqlRetentionPolicyMismatch { param_rp: String, query_rp: String },\n","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/core/iox_v1_query_api/src/error.rs#L40-L76","documentation":"The v1 query API needs a target database, taken either from the `db` request parameter or from the query itself (e.g. `ON <db>` clause). When neither is present this error is thrown. It prevents executing a query with no resolvable namespace.","triggerScenarios":"GET/POST to the v1 /query endpoint without a `db` parameter and with an InfluxQL statement that does not specify a database (no `ON` clause), e.g. `GET /query?q=SELECT * FROM cpu`.","commonSituations":"Forgetting the `db` query parameter when migrating 1.x clients; dropping the `ON` clause when converting queries; misconfigured dashboards that omit the datasource default DB.","solutions":["Add the `db` query parameter to the request, e.g. `?db=mydb&q=...`.","Alternatively include the database in the query: `SELECT * FROM \"mydb\".\"autogen\".cpu`.","Configure the client/datasource default database so `db` is always sent."],"exampleFix":"// before\nGET /query?q=SELECT+*+FROM+cpu\n// after\nGET /query?db=mydb&q=SELECT+*+FROM+cpu","handlingStrategy":"validation","validationCode":"function resolveDatabase(params, q) {\n  const onMatch = /\\bON\\s+[\"'`]?([\\w-]+)/i.exec(q);\n  if (!params.db && !onMatch) {\n    throw new Error(\"query requires a 'db' parameter or ON <db> clause\");\n  }\n  return params.db ?? onMatch[1];\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always send the `db` parameter from a single well-known client config value.","Centralize query construction so the database is injected in one place.","Include the database in fully-qualified FROM clauses when omitting `db`."],"tags":["influxql","query","missing-parameter","database"],"backgroundTag":"missing-required-argument","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}