{"record":{"id":"4ace49ae260d979d","repo":"actualbudget/actual","slug":"table-is-required-or-use-file-or-last","errorCode":null,"errorMessage":"--table is required (or use --file or --last)","messagePattern":"--table is required \\(or use --file or --last\\)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/query.ts","lineNumber":162,"sourceCode":"function buildQueryFromFlags(cmdOpts: Record<string, string | undefined>) {\n  const last = cmdOpts.last ? parseIntFlag(cmdOpts.last, '--last') : undefined;\n\n  if (last !== undefined) {\n    if (cmdOpts.table && cmdOpts.table !== 'transactions') {\n      throw new Error(\n        '--last implies --table transactions. Cannot use with --table ' +\n          cmdOpts.table,\n      );\n    }\n    if (cmdOpts.limit) {\n      throw new Error('--last and --limit are mutually exclusive');\n    }\n  }\n\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","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/cli/src/commands/query.ts#L144-L180","documentation":"The `query` command needs to know which table to query. If neither `--table` was given nor a `--file` with a `\"table\"` field was used nor `--last` (which implies transactions), `buildQueryFromFlags` throws this error telling you the three ways to supply one.","triggerScenarios":"Running `actual query` bare, or with only filter/select flags like `--where \"amount > 0\"`, with no `--table`, `--file`, or `--last`.","commonSituations":"First-time users typing `actual query --where ...` expecting a default table; scripts dropping the table argument from a templated command.","solutions":["Add `--table transactions` (or another valid table such as accounts, categories, payees).","Or use `--last N` to query the most recent transactions.","Or use `--file q.json` where the JSON contains a `\"table\"` field."],"exampleFix":"// before\nactual query --where \"amount > 0\"\n// after\nactual query --table transactions --where \"amount > 0\"","handlingStrategy":"validation","validationCode":"if (!table && !file && last === undefined) {\n  throw new Error('query needs --table, --file, or --last');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await cli(['query', ...args]);\n} catch (e) {\n  if (e.message.includes('--table is required')) {\n    console.error('Add --table <name>, --file <q.json>, or --last <n>');\n  }\n}","preventionTips":["Default to --table transactions when unsure.","Check that templated commands actually substitute the table argument.","Use --file for complex queries so the table lives inside the JSON."],"tags":["cli","validation","missing-argument","query"],"backgroundTag":"missing-required-argument","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}