clockworklabs/SpacetimeDB · error · TypeError

Index ' ' on table ' ' must define a non-empty 'accessor

Error message

Index '${indexLabel}' on table '${tableLabel}' must define a non-empty 'accessor'

What it means

When materializing a view, the host compiles the view's SQL with SubscriptionPlan::compile — the same compiler used for client subscriptions. If the plan reports parameters (has_params, i.e. '?' placeholders in the query), the host bails: views are materialized server-side at publish time, so there is no client to bind parameter values.

Solutions

  1. Inline concrete literals into the view query instead of '?' placeholders.
  2. If the filter must vary, materialize per-case views with different literals, or move the logic into a reducer that writes a regular table.
  3. For client-side parameterized reads, use a subscription against the underlying table rather than a view.

Example fix

-- before
CREATE VIEW active_users AS SELECT * FROM users WHERE level > ?;

-- after
CREATE VIEW active_users AS SELECT * FROM users WHERE level > 5;
Defensive patterns

Strategy: validation

Validate before calling

fn view_has_params(sql: &str) -> bool {
    let mut quoted = false;
    for c in sql.chars() {
        match c {
            '\'' => quoted = !quoted,
            '?' if !quoted => return true,
            _ => {}
        }
    }
    false
}
assert!(!view_has_params(&view_sql), "views cannot use ? parameters");

Prevention

When it happens

Trigger: Publishing a module or schema whose view definition contains '?' placeholders, e.g. CREATE VIEW v AS SELECT * FROM t WHERE t.x > ? — SubscriptionPlan::compile succeeds but sets has_params=true.

Common situations: Copying a parameterized subscription query into a view definition; assuming views behave like prepared statements; porting SQL from a client that binds filters dynamically.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20). Data as JSON: /api/errors/88fb7542690aff9e. Report an issue: GitHub.

Appendix: source

Thrown at crates/bindings-typescript/src/lib/table.ts:442

        colId: colIds.get(name)!,
        value: writer.getBuffer(),
      });
    }

    // If this column is shaped like ScheduleAtAlgebraicType, mark it as the schedule‑at column
    const algebraicType = builder.typeBuilder.algebraicType;
    if (ScheduleAt.isScheduleAt(algebraicType)) {
      scheduleAtCol = colIds.get(name)!;
    }
  }

  // convert explicit multi‑column indexes coming from options.indexes
  for (const indexOpts of userIndexes ?? []) {
    const accessor = indexOpts.accessor;
    if (typeof accessor !== 'string' || accessor.length === 0) {
      const tableLabel = name ?? '<unnamed>';
      const indexLabel = indexOpts.name ?? '<unnamed>';
      throw new TypeError(
        `Index '${indexLabel}' on table '${tableLabel}' must define a non-empty 'accessor'`
      );
    }
    let algorithm: RawIndexAlgorithm;
    switch (indexOpts.algorithm) {
      case 'btree':
        algorithm = {
          tag: 'BTree',
          value: indexOpts.columns.map(c => colIds.get(c)!),
        };
        break;
      case 'hash':
        algorithm = {
          tag: 'Hash',
          value: indexOpts.columns.map(c => colIds.get(c)!),
        };
        break;
      case 'direct':

View on GitHub (pinned to 6dee26c6ef)