Async Queries
Handle long-running queries efficiently using asynchronous execution.
When to Use Async
Section titled “When to Use Async”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.
Example
Section titled “Example”import asynciofrom 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 functionquery_id = asyncio.run(run_async_query())