actualbudget/actual · error · Error

--last implies --table transactions. Cannot use with --table

Error message

--last implies --table transactions. Cannot use with --table ${cmdOpts.table}

What it means

The `--last` flag is a shorthand for querying the most recent transactions, so it implicitly forces the table to `transactions`. If you combine `--last` with an explicit `--table` set to anything other than `transactions`, the intent is contradictory and `buildQueryFromFlags` throws this error.

Source

Thrown at packages/cli/src/commands/query.ts:149

  if (Array.isArray(parsed.orderBy)) {
    queryObj = queryObj.orderBy(parsed.orderBy);
  }
  if (typeof parsed.limit === 'number') queryObj = queryObj.limit(parsed.limit);
  if (typeof parsed.offset === 'number') {
    queryObj = queryObj.offset(parsed.offset);
  }
  if (Array.isArray(parsed.groupBy)) {
    queryObj = queryObj.groupBy(parsed.groupBy);
  }
  return queryObj;
}

function buildQueryFromFlags(cmdOpts: Record<string, string | undefined>) {
  const last = cmdOpts.last ? parseIntFlag(cmdOpts.last, '--last') : undefined;

  if (last !== undefined) {
    if (cmdOpts.table && cmdOpts.table !== 'transactions') {
      throw new Error(
        '--last implies --table transactions. Cannot use with --table ' +
          cmdOpts.table,
      );
    }
    if (cmdOpts.limit) {
      throw new Error('--last and --limit are mutually exclusive');
    }
  }

  const table =
    cmdOpts.table ?? (last !== undefined ? 'transactions' : undefined);
  if (!table) {
    throw new Error('--table is required (or use --file or --last)');
  }

  if (!(table in TABLE_SCHEMA)) {
    throw new Error(
      `Unknown table "${table}". Available tables: ${AVAILABLE_TABLES}`,

View on GitHub (pinned to d4334cb6e6)

Solutions

  1. Drop `--table` entirely when using `--last` (it defaults to transactions).
  2. Keep `--table transactions` if you must state it explicitly.
  3. Replace `--last` with `--limit` and an appropriate filter if you meant to query a non-transactions table.

Example fix

// before
actual query --last 30 --table categories
// after
actual query --last 30
Defensive patterns

Strategy: validation

Validate before calling

if (last !== undefined && table !== undefined && table !== 'transactions') {
  throw new Error('--last only works with the transactions table');
}

Try / catch

try {
  await cli(['query', ...args]);
} catch (e) {
  if (e.message.includes('--last implies --table transactions')) {
    console.error('Drop --table or set it to transactions when using --last');
  }
}

Prevention

When it happens

Trigger: Running e.g. `actual query --last 30 --table categories` — `--last` with a `--table` value other than `transactions` (an omitted `--table` is fine because it defaults to transactions).

Common situations: Copy-editing a transactions query to point at another table while keeping `--last`; scripted flag composition that appends `--last` unconditionally.

Related errors


AI-assisted analysis of actualbudget/actual@d4334cb6e6 (2026-08-29). Data as JSON: /api/errors/4043a6582efd33cb. Report an issue: GitHub.