Skip to content

Commit c022318

Browse files
committed
Document SQLAlchemy connection URL parameters.
Add README guidance for dialect URL parameters, DBAPI connect_args, and the enable_multirow_insert_casts opt-out flag. Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
1 parent aa0d69b commit c022318

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,42 @@ engine = create_engine(
4646
)
4747
```
4848

49+
### Connection URL parameters and `connect_args`
50+
51+
The Databricks SQLAlchemy dialect accepts dialect-specific options in the
52+
SQLAlchemy connection URL query string:
53+
54+
| Parameter | Required | Default | Description |
55+
|-|-|-|-|
56+
| `http_path` | Yes | | HTTP path for the Databricks SQL warehouse or compute resource. |
57+
| `catalog` | Yes | | Initial catalog for the connection. |
58+
| `schema` | Yes | | Initial schema for the connection. |
59+
| `enable_multirow_insert_casts` | No | `true` | Enables targeted casts for mixed scalar values in SQLAlchemy-generated multi-row `INSERT ... VALUES` statements. This avoids Spark inline-table type errors for pandas `to_sql(method="multi")` with mixed scalar/object columns. Set to `false` to disable this rewrite. |
60+
61+
For example, to disable targeted multi-row insert casts:
62+
63+
```python
64+
engine = create_engine(
65+
"databricks://token:dapi***@***.cloud.databricks.com"
66+
"?http_path=***&catalog=main&schema=test"
67+
"&enable_multirow_insert_casts=false"
68+
)
69+
```
70+
71+
Use SQLAlchemy's `connect_args` for DBAPI connection options that should be
72+
passed through to `databricks-sql-connector`, such as user-agent settings:
73+
74+
```python
75+
engine = create_engine(
76+
"databricks://token:dapi***@***.cloud.databricks.com"
77+
"?http_path=***&catalog=main&schema=test",
78+
connect_args={"user_agent_entry": "My SQLAlchemy App"},
79+
)
80+
```
81+
82+
Dialect URL parameters control SQLAlchemy compilation behavior and are not
83+
forwarded to the DBAPI connector.
84+
4985
## Types
5086

5187
The [SQLAlchemy type hierarchy](https://docs.sqlalchemy.org/en/20/core/type_basics.html) contains backend-agnostic type implementations (represented in CamelCase) and backend-specific types (represented in UPPERCASE). The majority of SQLAlchemy's [CamelCase](https://docs.sqlalchemy.org/en/20/core/type_basics.html#the-camelcase-datatypes) types are supported. This means that a SQLAlchemy application using these types should "just work" with Databricks.

0 commit comments

Comments
 (0)