Query a table or view
query_tableRun read-only SELECT queries on one table or view with filters, grouping, aggregates, pagination, and sampling, returning row_count and a truncated flag.
Instructions
Runs a SELECT on one table or view, with optional column list, filter, ordering, grouping, aggregates (COUNT, SUM, AVG, MIN, MAX), pagination and random sampling, and returns the rows in an object with row_count and a measured 'truncated' flag, so a short result is never mistaken for a complete one. Rows are capped by the database's max_query_rows. Call get_table_schema first for exact column names; for null ratios, distinct counts and frequent values use get_data_profile instead of paging through rows. Reads actual data; never runs INSERT, UPDATE, DELETE or procedures.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| top | No | Maximum number of rows to return (default 100, capped by the per-database limit). | |
| skip | No | Number of rows to skip before returning results (for pagination, default 0). | |
| table | Yes | Table or view name, bare, with no schema prefix. Example: 'GenericSecurity' | |
| where | No | WHERE clause without the WHERE keyword, as SQL. Example: "Source = 'BDS' AND ReferenceDate >= '2026-01-01'" | |
| schema | No | Table/view schema. Empty means dbo. Example: 'Feeder' | |
| columns | No | Columns as ONE comma-separated string, not a JSON array. Example: 'ReferenceDate, Source, Close'. Empty or '*' returns every column. Reserved words need no quoting or brackets. | |
| database | Yes | Name of the database as registered in the configuration. | |
| group_by | No | GROUP BY columns as ONE comma-separated string. Example: 'Source, Name' | |
| order_by | No | ORDER BY clause without the ORDER BY keyword. Example: 'ReferenceDate DESC, Name' | |
| aggregates | No | Aggregates as ONE comma-separated string of FUNC(column) [AS alias], with FUNC one of COUNT, SUM, AVG, MIN, MAX. Only a bare column name is allowed inside the parentheses. Example: 'COUNT(*) AS Total, MAX(ReferenceDate) AS Ultima' | |
| sample_percent | No | Random sampling percentage, from 0.01 to 100. Zero (the default) means no sampling. |