Skip to content

Executing Queries

Execute SQL queries against Komodo’s Snowflake data warehouse using standard DB-API 2.0 patterns.

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.

The get_snowflake_connection() function returns a DB-API 2.0 compliant connection:

from komodo import get_snowflake_connection
conn = get_snowflake_connection()

Use cursors to execute queries:

cursor = conn.cursor()
# Execute a query
cursor.execute("USE DATABASE DATA")
cursor.execute("SELECT column_name, table_name FROM INFORMATION_SCHEMA.COLUMNS LIMIT 20")
# Fetch results
rows = cursor.fetchall()
print(f"Found {len(rows)} columns")
cursor.close()
conn.close()
cursor.execute("SELECT * FROM INFORMATION_SCHEMA.COLUMNS")
all_rows = cursor.fetchall()
cursor.execute("SELECT * FROM INFORMATION_SCHEMA.COLUMNS LIMIT 1")
row = cursor.fetchone()
print(row)
cursor.execute("SELECT * FROM INFORMATION_SCHEMA.COLUMNS LIMIT 100")
# Fetch 10 rows at a time
batch = cursor.fetchmany(size=10)

The Komodo CLI provides commands for executing SQL statements without writing Python code. These are useful for quick ad-hoc queries and exploration.

Before using the SQL CLI commands, authenticate and set your account:

Terminal window
uv run komodo login
Terminal window
uv run komodo account set

Run a SQL statement directly from the command line with sql-execute:

Terminal window
uv run komodo sql-execute "SELECT column_name, table_name FROM INFORMATION_SCHEMA.COLUMNS LIMIT 20"

Results are displayed in a formatted table. Use the --environment or -E flag to target a specific environment (e.g., integration):

Terminal window
uv run komodo sql-execute -E integration "USE DATABASE DATA"

For running multiple queries in a session, use the interactive sql-shell:

Terminal window
uv run komodo sql-shell

The 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.

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.