Skip to content

Async Queries

Handle long-running queries efficiently using asynchronous execution.

Use async query execution for:

  • Long-running queries: Queries taking several seconds or minutes
  • Large datasets: Processing millions of rows
  • Analytical queries: Complex aggregations and joins

For quick queries (< 1 second), use regular synchronous execution.

import asyncio
from komodo import get_snowflake_connection, execute_query_async
async def run_async_query():
# Create connection and cursor
conn = get_snowflake_connection()
cursor = conn.cursor()
cursor.execute("USE DATABASE DATA")
query = "SELECT column_name, table_name FROM INFORMATION_SCHEMA.COLUMNS LIMIT 20"
cursor = await execute_query_async(cursor=cursor, query=query)
# Fetch results after query completes
rows = cursor.fetchall()
print(f"Query returned {len(rows)} rows")
cursor.close()
conn.close()
# Run the async function
query_id = asyncio.run(run_async_query())