execute_query
Execute read-only SQL queries on Snowflake and return results as compact text, with optional database and schema context.
Instructions
Execute a read-only SQL query (SELECT, SHOW, DESCRIBE, WITH) and return results.
Requires a populated schema cache; auto-refreshes on first use if empty.
Parameters:
- sql: read-only SQL query
- database: optional database context
- schema: optional schema context
Returns a compact TEXT payload (not JSON): a `key: value` header
(status, rows, cols, execution_time, query_id), a `---` separator, then a
result block whose shape depends on row count:
- ONE row: aligned `NAME value` lines (one column per line), any width.
- 2+ narrow rows: positional TSV (line 1 = tab-separated column names, one
row per line after). Parse with awk/cut, e.g. `awk -F'\t' 'NR>1 && $3=="X"'`.
NULL = `\N`; tabs/newlines escaped so each field is one line.
Multi-row results that are wide, tall, or too large auto-spill the COMPLETE
result to a temp `.tsv` file; the payload then carries `results_file` and
`column_index` (name->position) and NO inline rows. Read/grep/awk the file
(it has its own header line); `rows:` is always the true total.
Example: execute_query("SELECT * FROM SALES_DB.PUBLIC.CUSTOMERS LIMIT 10")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | ||
| schema | No | ||
| database | No |