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. Use the --environment or -E flag to target a specific environment (e.g., integration):
uv run komodo sql-execute -E integration "USE DATABASE DATA"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.
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.