Executing Queries
Execute SQL queries against Komodo’s Snowflake data warehouse using standard DB-API 2.0 patterns.
Your Snowflake warehouse
Section titled “Your Snowflake warehouse”All Komodo data you are subscribed to lives in a Komodo-managed Snowflake warehouse provisioned for your account (accounts). The SDK gives you a DB-API 2.0 connection to that warehouse, so you can use familiar patterns: cursor.execute(), fetchone(), fetchall(), fetchmany(), and cursor.description for column metadata. That same connection works with pandas (read_sql, fetch_pandas_all, fetch_pandas_batches) and other tools that expect a standard Python database connection.
For more context on authentication and account selection, see Authentication.
Get a Connection
Section titled “Get a Connection”The get_snowflake_connection() function returns a DB-API 2.0 compliant connection:
from komodo import get_snowflake_connection
conn = get_snowflake_connection()Execute Queries
Section titled “Execute Queries”Use cursors to execute queries:
cursor = conn.cursor()
# Execute a querycursor.execute("USE DATABASE DATA")cursor.execute("SELECT column_name, table_name FROM INFORMATION_SCHEMA.COLUMNS LIMIT 20")
# Fetch resultsrows = cursor.fetchall()print(f"Found {len(rows)} columns")
cursor.close()conn.close()Fetching Results
Section titled “Fetching Results”Fetch All Rows
Section titled “Fetch All Rows”cursor.execute("SELECT * FROM INFORMATION_SCHEMA.COLUMNS")all_rows = cursor.fetchall()Fetch One Row
Section titled “Fetch One Row”cursor.execute("SELECT * FROM INFORMATION_SCHEMA.COLUMNS LIMIT 1")row = cursor.fetchone()print(row)Fetch Multiple Rows
Section titled “Fetch Multiple Rows”cursor.execute("SELECT * FROM INFORMATION_SCHEMA.COLUMNS LIMIT 100")# Fetch 10 rows at a timebatch = cursor.fetchmany(size=10)CLI Commands
Section titled “CLI Commands”The Komodo CLI provides commands for executing SQL statements without writing Python code. These are useful for quick ad-hoc queries and exploration.
Prerequisites
Section titled “Prerequisites”Before using the SQL CLI commands, authenticate and set your account:
uv run komodo loginuv run komodo account setExecute a Single Query
Section titled “Execute a Single Query”Run a SQL statement directly from the command line with sql-execute:
uv run komodo sql-execute "SELECT column_name, table_name FROM INFORMATION_SCHEMA.COLUMNS LIMIT 20"Results are displayed in a formatted table.
Interactive SQL Shell
Section titled “Interactive SQL Shell”For running multiple queries in a session, use the interactive sql-shell:
uv run komodo sql-shellThe shell prompts you to enter SQL statements. Type exit when finished. Each query’s results are displayed as a table. Errors in one statement do not exit the shell—you can continue running queries. The --environment / -E flag works the same as with sql-execute.
Inspecting failures
Section titled “Inspecting failures”When a query fails, the SDK now surfaces the full Snowflake error — message, error code, SQL state, and query ID — instead of a generic message. A failed cursor.execute() raises with detail like:
Komodo Error: Failure during expansion of view 'MEDICAL_SERVICE_LINES_LATEST': Error in secure object. | Error code: 002003 | SQL state: 02000 | Query ID: 01b... (Trace ID: ...)To investigate a query after the fact, use its query ID (cursor.sfqid, also shown as Query ID: in the error) to fetch diagnostics:
from komodo import get_snowflake_connection, get_query_diagnostics
conn = get_snowflake_connection()cursor = conn.cursor()cursor.execute("USE DATABASE DATA")try: cursor.execute("SELECT * FROM SOME_SECURE_VIEW")except Exception as err: print(err) # full Snowflake error, with Query ID diagnostics = get_query_diagnostics(conn, cursor.sfqid) print(diagnostics) # error code/message, execution status, warehouse, timingget_query_diagnostics reads Snowflake’s INFORMATION_SCHEMA.QUERY_HISTORY for the current role/account, so a database must be set on the connection (e.g. USE DATABASE DATA) and the query must be within the history retention window. It returns None if no matching query is found. See Troubleshooting for more.
From the CLI
Section titled “From the CLI”uv run komodo sql-diagnostics <query-id>Exploring with MCP
Section titled “Exploring with MCP”If you use the MCP server, an AI assistant can call the list_snowflake tool to browse databases, schemas, tables, and columns for you. That helps you discover object names before you write SQL in Python or the CLI.