query_sql
Run read-only SQL SELECT queries against cached Tally data tables to analyze voucher items, stock, balances, and report snapshots without re-fetching from Tally.
Instructions
Run a read-only SQL SELECT query against this session's in-memory cache (gone when the session ends). Tables: ledgers(name, parent, closing_balance, trn, state, country), groups(name, parent), stock_items(name, parent, closing_balance), vouchers(guid, date, voucher_type, voucher_number, party_ledger, amount, narration), voucher_items(voucher_guid, date, voucher_type, voucher_number, stock_item, qty, rate, amount, is_deemed_positive, godown, batch) — all five populated only by explicitly calling sync_to_sql/sync_vouchers_to_sql/sync_voucher_items_to_sql first. Movement analysis, godown-wise stock, and batch/ageing detail are just SELECTs over voucher_items — there is no separate report tool for them. profit_and_loss(ledger_name, group_name, closing_balance, period_from, period_to), stock_summary(name, parent, opening_qty, closing_qty, opening_value, closing_value, as_of_date), balance_sheet(group_name, amount, as_of_date), trial_balance(name, debit_amount, credit_amount, period_from, period_to), and vat_summary(ledger_name, category, closing_balance, period_from, period_to) are populated automatically, no separate sync step — every get_profit_and_loss/get_stock_summary/get_balance_sheet/get_trial_balance/get_vat_liability_summary call refreshes its table with that call's result, so a follow-up question about the same report can query it here instead of re-fetching from Tally. Each of these five only ever holds the most recent call's data, not a history — re-call the report tool if you need a different period. set_company automatically empties every one of these tables when the active company changes, so a query never silently returns a previous company's rows — it just means every table is empty again right after switching, until re-synced/re-fetched.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | A single SELECT statement |