A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix(sql): resolve default database for snowflake engines without a database in the URL (#10616)
sha2fiddyd5aedfaad59a
diff --git a/docs/_static/docs-sql-discovery-settings.png b/docs/_static/docs-sql-discovery-settings.pngnew file mode 100644index 0000000000..9de8bb4370Binary files /dev/null and b/docs/_static/docs-sql-discovery-settings.png differdiff --git a/docs/guides/working_with_data/sql.md b/docs/guides/working_with_data/sql.mdindex 3303d7f933..01e575012c 100644--- a/docs/guides/working_with_data/sql.md+++ b/docs/guides/working_with_data/sql.md@@ -393,15 +393,21 @@ marimo will automatically discover the database connection and display the datab???+ note- By default, marimo auto-discovers databases and schemas, but not tables and columns (to avoid performance issues with large databases). You can configure this behavior in your `pyproject.toml` file. Options are `true`, `false`, or `"auto"`. `"auto"` will determine whether to auto-discover based on the type of database (e.g. when the value is `"auto"`, Snowflake and BigQuery will not auto-discover tables and columns while SQLite, Postgres, and MySQL will):+ By default, marimo auto-discovers databases but may not discover tables, columns and schemas (to avoid performance issues with large databases). You can configure this behavior in your `pyproject.toml` file. Options are `true`, `false`, or `"auto"`. `"auto"` will determine whether to discover based on the type of database: databases that are cheap to introspect (e.g. SQLite, Postgres, MySQL) are discovered, while data warehouses (e.g. Snowflake, BigQuery) are not:```toml title="pyproject.toml"[tool.marimo.datasources]- auto_discover_schemas = true # Default: true+ auto_discover_schemas = "auto" # Default: "auto"auto_discover_tables = "auto" # Default: "auto"- auto_discover_columns = "auto" # Default: false+ auto_discover_columns = false # Default: false```+ SQL cell autocompletion relies on discovery so it may not work if the schema has not been discovered. You can either use the Data Sources panel and expand the schemas and tables you want which will register the autocompletion semantics, or change the config set above.++ You can also change these settings through the notebook settings menu (gear icon), under **Packages & Data**:++ <img width="700" src="/_static/docs-sql-discovery-settings.png" alt="Database schema discovery settings" />+## Catalogsmarimo supports connecting to Iceberg catalogs. You can click the "+" button in the Datasources panel or manually create a [PyIceberg](https://py.iceberg.apache.org/) `Catalog` connection. PyIceberg supports a variety of catalog implementations including REST, SQL, Glue, DynamoDB, and more.diff --git a/marimo/_sql/engines/sqlalchemy.py b/marimo/_sql/engines/sqlalchemy.pyindex d8f3af67c9..89f8e987da 100644--- a/marimo/_sql/engines/sqlalchemy.py+++ b/marimo/_sql/engines/sqlalchemy.py@@ -256,6 +256,7 @@ class SQLAlchemyEngine(SQLConnection["Engine"]):"mssql": "SELECT DB_NAME()","timeplus": "SELECT current_database()","starrocks": "SELECT CATALOG()",+ "snowflake": "SELECT current_database()",}# Try to get the database name by querying the database directlydiff --git a/tests/_sql/test_sqlalchemy.py b/tests/_sql/test_sqlalchemy.pyindex c139354376..9f5479c6e6 100644--- a/tests/_sql/test_sqlalchemy.py+++ b/tests/_sql/test_sqlalchemy.py@@ -1282,3 +1282,15 @@ def test_snowflake_get_database_names_delegates(make_engine):mocked.assert_called_once()assert result == expected++[email protected](not HAS_SQLALCHEMY, reason="SQLAlchemy not installed")+def test_snowflake_default_database_queried_when_not_in_url(make_engine):+ """Snowflake falls back to querying the current database when the+ connection URL has no database (e.g. engines built with `creator=`)."""+ engine = make_engine(default_database=None)+ engine._mock_conn.execute.return_value.fetchone.return_value = ("MY_DB",)++ assert engine.get_default_database() == "MY_DB"+ executed_sql = engine._mock_conn.execute.call_args[0][0]+ assert str(executed_sql) == "SELECT current_database()"