{"record":{"id":"e2b464aa87b953a2","repo":"actualbudget/actual","slug":"count-and-select-are-mutually-exclusive","errorCode":null,"errorMessage":"--count and --select are mutually exclusive","messagePattern":"--count and --select are mutually exclusive","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/query.ts","lineNumber":176,"sourceCode":"\n  const table =\n    cmdOpts.table ?? (last !== undefined ? 'transactions' : undefined);\n  if (!table) {\n    throw new Error('--table is required (or use --file or --last)');\n  }\n\n  if (!(table in TABLE_SCHEMA)) {\n    throw new Error(\n      `Unknown table \"${table}\". Available tables: ${AVAILABLE_TABLES}`,\n    );\n  }\n\n  if (cmdOpts.where && cmdOpts.filter) {\n    throw new Error('--where and --filter are mutually exclusive');\n  }\n\n  if (cmdOpts.count && cmdOpts.select) {\n    throw new Error('--count and --select are mutually exclusive');\n  }\n\n  let queryObj = api.q(table);\n\n  if (cmdOpts.count) {\n    queryObj = queryObj.calculate({ $count: '*' });\n  } else if (cmdOpts.select) {\n    queryObj = queryObj.select(cmdOpts.select.split(','));\n  } else if (last !== undefined) {\n    queryObj = queryObj.select(LAST_DEFAULT_SELECT);\n  }\n\n  const filterStr = cmdOpts.filter ?? cmdOpts.where;\n  if (filterStr) {\n    queryObj = queryObj.filter(JSON.parse(filterStr));\n  }\n\n  const orderByStr =","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/cli/src/commands/query.ts#L158-L194","documentation":"The `actual query` command supports `--count` (returns only the number of matching rows) and `--select` (choose which fields to return). Counting discards row projection entirely, so passing both is rejected by buildQueryFromFlags before the query runs.","triggerScenarios":"Running `actual query transactions --count --select date,amount` — both flags present. Also occurs when a shell alias or wrapper always adds --select while the user adds --count.","commonSituations":"Users wanting totals per-field assume --count works with --select; scripts migrating commands that previously selected fields to a counting variant.","solutions":["Drop --select when using --count; the result is a single { count: N } object","If you need per-group counts, use --group-by with --count or select the field and count rows client-side","If you need the rows, drop --count and keep --select"],"exampleFix":"// before\nactual query transactions --count --select date,amount\n\n// after\nactual query transactions --count","handlingStrategy":"validation","validationCode":"const flags = ['--count', ...(select ? ['--select', select] :) []];\nif (useCount && select) throw new Error('--select is meaningless with --count; remove one');","typeGuard":"function hasCountSelectConflict(opts: { count?: boolean; select?: string }): boolean {\n  return opts.count === true && opts.select !== undefined;\n}","tryCatchPattern":"try {\n  await run(['actual', 'query', table, ...flags]);\n} catch (e) {\n  if (String(e.message).includes('--count and --select')) {\n    console.error('Use --count alone, or --select for row data');\n  } else throw e;\n}","preventionTips":["Treat --count as a standalone mode: count OR select, never both","For group totals, use --group-by with --count rather than selecting","Review shell wrappers that hardcode --select before appending --count"],"tags":["cli","aql","invalid-flags","mutually-exclusive-options"],"backgroundTag":"mutually-exclusive-cli-options","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}