execute_query
Run read-only SQL queries (SELECT, SHOW, DESCRIBE, WITH) on Snowflake and retrieve results in TSV format, with automatic handling of large result sets.
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
positional TSV block. TSV rules: line 1 = tab-separated column names, one row
per line after; NULL = `\N`; tabs/newlines escaped so each row is one line.
Parse with awk/cut, e.g. `awk -F'\t' 'NR>1 && $3=="X"'`.
Large/wide/tall results auto-spill the COMPLETE result to a temp `.tsv` file;
the payload then carries `results_file`, `column_index` (name->position), and a
`spilled` marker in place of inline rows. Read/grep/awk the file; `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 | ||
| database | No | ||
| schema | No |