# Query Result Tables

Every query result is a readable, structured table — right in the chat. Column types, numeric alignment, NULL handling, and execution stats are rendered automatically so you can scan results without switching to a spreadsheet.

Note
Query result tables are rendered client-side from the raw output of `tdx query`. The AI detects query output automatically and displays it as a structured table rather than plain text. No additional processing is required from you.

## Objective

Read and interpret query results inline in the chat stream, including column types, formatted values, execution metadata, and error diagnostics.

## Prerequisites

- Signed in to Treasure AI Studio ([Getting Started](/products/ai-studio/getting-started))
- A completed query execution (see [Query Execution](/products/ai-studio/query/query-execution))
- **Web or Desktop only** — query result tables are not available on Mobile


## Table Layout

Query result tables display inline in the chat, below the tool call that produced them. The table auto-expands when results are detected during streaming.

### Structure

| Section | Description |
|  --- | --- |
| **Header row** | Column names in bold, with the column type displayed in smaller text below each name (e.g., `varchar`, `bigint`, `double`) |
| **Data rows** | Query results with formatting based on data type |
| **Stats row** | Execution metadata below the table |


The header row is **sticky** — it stays visible as you scroll through long result sets. The table has a maximum height of 300 pixels with vertical scrolling for large results, and horizontal scrolling for wide tables.

## Column Types and Formatting

The table formats values based on the column type reported by the query engine.

### Numeric Values

Columns with numeric types are **right-aligned** with tabular number formatting for easy column scanning. Recognized numeric types:

`int`, `bigint`, `double`, `float`, `decimal`, `smallint`, `tinyint`, `real`, `long`, `number`

All other types are left-aligned.

### Special Values

| Value | Display |
|  --- | --- |
| **NULL** | Displayed as `NULL` in italic, muted text |
| **true** | Displayed in green text |
| **false** | Displayed in muted text |
| **Strings** | Displayed as-is |


### Row Highlighting

Hover over any row to highlight it with a subtle background — useful for tracking across wide tables with many columns.

## Execution Stats

Below the result table, a stats row shows metadata about the query execution. The format is:

> **X rows** · **Processed Y rows** · **in Z** · **Job N**


| Stat | Description | Example |
|  --- | --- | --- |
| **Row count** | Number of rows returned | `42 rows` |
| **Processed rows** | Total rows scanned by the Trino engine | `Processed 1.2M rows` |
| **Elapsed time** | Query execution duration (latency) | `in 3.2s` |
| **Job ID** | Treasure AI job identifier | `Job 987654321` |


Not all stats are present for every query. The stats row shows only the fields available from the query engine output.

Pro Tip
The Job ID can be used to look up the query in the Treasure AI console for detailed execution plans, resource usage, and logs. High "Processed rows" relative to returned rows may indicate missing partition pruning — use `/sql-skills:trino-optimizer` to diagnose.

## Error Display

When a query fails, the result table is replaced by an **error card**:

The error card includes:

| Element | Description |
|  --- | --- |
| **Warning icon** | Red triangle indicating a failure |
| **"Query failed"** label | Header text in red |
| **SQL** | The query that was executed, in monospace |
| **Error message** | The full error text from the query engine |
| **Job ID** | Treasure AI job identifier (when available) |


Common error scenarios:

| Error | Cause | Fix |
|  --- | --- | --- |
| Table not found | Wrong database or table name | Ask the AI to run `tdx databases` and `tdx tables <db>` to verify |
| Column not found | Misspelled or non-existent column | Ask the AI to run `tdx describe <db.table>` to check schema |
| Permission denied | Insufficient access to the database | Contact your Treasure AI administrator |
| Syntax error | Invalid SQL | Review the SQL in the error card and correct the syntax |


## Reading Results in Context

Query result tables appear as part of the conversation flow. After the table renders, the AI typically provides analysis or next steps based on the results. For example:

1. You ask: "What are the top 5 customers by revenue?"
2. The AI runs: `tdx query "SELECT customer_id, SUM(revenue) AS total ... LIMIT 5"`
3. A result table renders with 5 rows
4. The AI summarizes: "Customer ID 12345 leads with $2.3M in total revenue..."


The AI can reference the results in subsequent messages because the query output is part of the conversation context.

## Tool Call Integration

Query results live inside **tool call indicators**. Each query execution shows:

1. **Status icon** — Spinning (running), green checkmark (completed), or red X (error)
2. **Description** — What the tool is doing (e.g., the Bash command description)
3. **Command preview** — The full command in monospace, truncated to one line
4. **Expand/collapse** — Click to toggle the full command text and result
5. **Copy button** — Appears on hover; copies the command text to your clipboard
6. **Duration badge** — Shows execution latency if 1 second or longer (e.g., "3.2s")
7. **Exit code badge** — Shows "Exit 1" (red) if the command returned a non-zero exit code


Query results auto-expand when detected during streaming, so you see the table without needing to click.

Technical Note
Tool call results longer than 12 lines show a "Show N more lines" link. However, query results bypass this truncation — they always render as a full `QueryResultTable` component with their own 300px scrollable viewport.

## Current Limitations

The query result table is designed for **viewing query output inline**. The following features are not available in the current release:

- **Sorting** — Columns are not sortable in the rendered table. To re-sort results, ask the AI to re-run the query with an `ORDER BY` clause.
- **Filtering** — No client-side row filtering. Add `WHERE` clauses to your query for filtering.
- **Pagination** — All returned rows display in a scrollable viewport (max 300px height). For large result sets, use `LIMIT` in your query.
- **Export** — No direct CSV/Excel export from the table. To export results, ask the AI to save output to a file using `tdx query --output results.csv "..."`.
- **Column resizing** — Column widths are fixed based on content.


Pro Tip
For full spreadsheet features (sorting, filtering, resizing), ask the AI to save query results as a CSV or XLSX file. You can then open it in the [Spreadsheet Viewer](/products/ai-studio/files/file-viewers#spreadsheet-viewer) which supports sorting and resizable columns.

## Verification

- [ ] See column headers with type annotations (e.g., `bigint`, `varchar`) below each name
- [ ] See numeric columns right-aligned and NULL values in italic muted text
- [ ] See a stats row below the table with row count and execution time


## Troubleshooting

| Issue | Solution |
|  --- | --- |
| Table shows raw text instead of a formatted table | Ensure the command uses `tdx query` (not a raw SQL client) so the output includes the expected format that Studio can parse |
| Column types not shown | Type annotations appear below column headers. If missing, the query output may not include schema metadata — run the query via the AI rather than a direct command |
| Stats row not visible | The stats row appears below the table only for queries executed via `tdx query`. Direct SQL output may not include execution metadata |


## Next Steps

- [Query Execution](/products/ai-studio/query/query-execution) — Running queries through the AI and direct commands
- [TDX Commands](/products/ai-studio/query/tdx-commands) — Full CLI command reference
- [File Viewers](/products/ai-studio/files/file-viewers) — Spreadsheet viewer for exported results
- [Charts & Data Visualization](/products/ai-studio/visualization/charts) — Visualizing query results