MCPcopy
hub / github.com/marimo-team/marimo / execute_duckdb_query

Function execute_duckdb_query

marimo/_data/get_datasets.py:106–127  ·  view source on GitHub ↗

Execute a DuckDB query and return the result. Uses connection if provided, otherwise uses duckdb.

(
    connection: duckdb.DuckDBPyConnection | None, query: str
)

Source from the content-addressed store, hash-verified

104
105
106def execute_duckdb_query(
107 connection: duckdb.DuckDBPyConnection | None, query: str
108) -> list[Any]:
109 """Execute a DuckDB query and return the result. Uses connection if provided, otherwise uses duckdb."""
110 try:
111 if connection is None:
112 import duckdb
113
114 return duckdb.execute(query).fetchall()
115
116 return connection.execute(query).fetchall()
117 except Exception as e:
118 if DependencyManager.duckdb.has():
119 import duckdb
120
121 # Connection is closed, return empty result
122 if isinstance(e, duckdb.ConnectionException):
123 LOGGER.debug("Skipping query on closed DuckDB connection")
124 return []
125
126 LOGGER.exception("Failed to execute DuckDB query %s", query)
127 return []
128
129
130def get_databases_from_duckdb(

Callers 3

get_table_columnsFunction · 0.85

Calls 4

executeMethod · 0.45
hasMethod · 0.45
debugMethod · 0.45
exceptionMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…