influxdata/influxdb · error · Error

error in InfluxQL statement

Error message

error in InfluxQL statement: {0}

What it means

Wraps rewrite::Error raised while rewriting an InfluxQL statement into the internal query representation. InfluxQL (the InfluxDB 1.x query language) must be translated before execution, and statements using unsupported constructs fail here with `error in InfluxQL statement: {0}`.

Solutions

  1. Read the inner rewrite error to see which statement/clause failed.
  2. Rewrite the query using supported InfluxQL or convert it to SQL for the /api/v3/query_sql endpoint.
  3. Check the InfluxDB 3.x InfluxQL support documentation for unsupported functions and clauses.
  4. Split multi-clause or exotic queries into simpler supported statements.

Example fix

// before
SELECT moving_average(mean(value), 5) FROM cpu WHERE time > now() - 1h
// after
-- use a supported construct or SQL windowing
SELECT mean(value) FROM cpu WHERE time > now() - 1h GROUP BY time(5m)
Defensive patterns

Strategy: validation

Validate before calling

// check statement against the supported InfluxQL function/clause allowlist before sending
if (!SUPPORTED_INFLUXQL_RE.test(q)) convertToSql(q);

Try / catch

try { await influxqlQuery(q); } catch (e) { if (e.message.startsWith('error in InfluxQL statement')) return fallbackToSql(q); throw e; }

Prevention

When it happens

Trigger: Sending an InfluxQL query via the /query (v1-compatibility) endpoint whose statement contains unsupported selectors, clauses, or functions that the rewriter cannot translate.

Common situations: Migrating from InfluxDB 1.x and reusing 1.x queries verbatim; using SHOW/GRANT/RETENTION statements not supported by the 3.x rewriter; exotic subqueries or continuous-query syntax.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19). Data as JSON: /api/errors/94f72739d8d6a497. Report an issue: GitHub.

Appendix: source

Thrown at influxdb3_server/src/http.rs:329

    #[error("serde json error: {0}")]
    Influxdb3Write(#[from] influxdb3_write::Error),

    #[error("datafusion error: {0}")]
    Datafusion(#[from] DataFusionError),

    #[error("io error: {0}")]
    Io(#[from] std::io::Error),

    #[error("query error: {0}")]
    Query(#[from] QueryExecutorError),

    #[error(transparent)]
    DbName(#[from] ValidateDbNameError),

    #[error("partial write of line protocol occurred")]
    PartialLpWrite(BufferedWriteRequest),

    #[error("error in InfluxQL statement: {0}")]
    InfluxqlRewrite(#[from] rewrite::Error),

    #[error("must provide only one InfluxQl statement per query")]
    InfluxqlSingleStatement,

    #[error("must specify a 'db' parameter, or provide the database in the InfluxQL query")]
    InfluxqlNoDatabase,

    #[error(
        "provided a database in both the parameters ({param_db}) and \
        query string ({query_db}) that do not match, if providing a query \
        that specifies the database, you can omit the 'database' parameter \
        from your request"
    )]
    InfluxqlDatabaseMismatch { param_db: String, query_db: String },

    #[error("Operation with object store failed: {0}")]
    ObjectStore(#[from] object_store::Error),

View on GitHub (pinned to 06200ef96b)