Writing named SQL queries for a data warehouse
Updated June 14, 2026
Adding queries
Click Queries on a warehouse row to open the query editor panel. Each query has a Name (e.g. "Customer Orders") and a SQL statement. Click Add Query to add more, then Save Queries.
Placeholder variables
SQL queries can reference the current conversation's customer data using curly-brace placeholders. These are safely substituted (SQL-escaped) before execution:
{customer_id}— the customer ID{email}— the customer's email address{name}— the customer's display name{session_id}— the current conversation ID
Example:
SELECT * FROM orders WHERE customer_id = '{customer_id}'Safety constraints
- Only SELECT statements are permitted. Any attempt to save a query containing DML or DDL (INSERT, UPDATE, DELETE, DROP, etc.) is rejected.
- A
LIMIT 100clause is automatically appended if not already present, preventing accidental full-table scans.
How results appear in conversations
On the first message of a conversation, all active warehouse queries are executed in parallel. Each query's results are injected as a separate section:
## Warehouse Data: {warehouse name} — {query name}Results are cached on the conversation, so subsequent messages reuse the same data. Queries that fail are silently skipped and never block the AI response.
