query_sql
Run read-only SQL SELECT queries against Tally data cached in memory to build custom reports, analyze movements, or reconcile ledgers 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), voucher_ledger_entries(voucher_guid, date, voucher_type, voucher_number, ledger, amount, is_deemed_positive, cost_centre, bill_name, bill_type) — all six populated only by explicitly calling sync_to_sql/sync_vouchers_to_sql/sync_voucher_items_to_sql/sync_voucher_ledger_entries_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. Splitting a ledger's balance apart by voucher (e.g. a combined VAT ledger into Output vs Input), or reconciling a party ledger's movements voucher by voucher, is just a SELECT over voucher_ledger_entries the same way — voucher_ledger_entries.amount is signed (negative debit, positive credit), so GROUP BY ledger, voucher_type with SUM(amount) is the natural query. 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), vat_summary(ledger_name, category, closing_balance, period_from, period_to), and gst_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/get_gst_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 six only ever holds the most recent call's data, not a history — re-call the report tool if you need a different period. Every call here checks which company is actually open in Tally right now against what the cache was last synced/queried for, however that company was arrived at (set_company, Tally's own UI, or a connector restart) — a mismatch clears the stale cache and refuses to run, rather than silently answering with a previous company's rows under the new company's name.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | A single SELECT statement |