Skip to main content
Execute a SQL query. By default, this uses duckdb to execute the query. Any dataframes in the global namespace can be used inside the query. You can also pass a custom engine to execute queries against other databases.

Usage

Signature

Parameters

str
required
The SQL query to execute.
bool
default:"True"
Whether to display the result in the UI.
Optional[DBAPIConnection]
default:"None"
Optional SQL engine to use. Can be a SQLAlchemy, DuckDB, Clickhouse, Redshift, Ibis, or DB-API 2.0 compatible connection (including ADBC drivers). If None, uses DuckDB.

Returns

The result of the query.

Supported Engines

  • DuckDB (default): Automatically uses DuckDB if no engine is specified
  • SQLAlchemy: Pass a SQLAlchemy engine or connection
  • Ibis: Pass an Ibis connection
  • Clickhouse: Pass a Clickhouse connection
  • Redshift: Pass a Redshift connection
  • DB-API 2.0: Any PEP 249 compatible connection
  • ADBC: DB-API wrappers provided by ADBC drivers

Default Result Limit

You can set a default result limit using the MARIMO_SQL_DEFAULT_LIMIT environment variable. If set, queries without an explicit LIMIT clause will be limited to this many rows.