Skip to content

Unable to insert Python lists into ARRAY<STRING> columns using pandas to_sql #73

Description

@Prajwal082

Description

Hello,

I am trying to insert Python lists into a Databricks
ARRAY<STRING> column using pandas DataFrame.to_sql() with
the Databricks SQLAlchemy dialect.

The table is created correctly with an ARRAY<STRING> column,
but the inserted arrays are stored as empty arrays.

Image

Minimal reproducible example

import pandas as pd
from sqlalchemy import create_engine, String, Integer
from sqlalchemy.dialects.postgresql import ARRAY
from urllib.parse import quote_plus

df = pd.DataFrame([
    {
        "GROUP_ID": 1,
        "PARAM": ["abc@mail.com", "xyz@mail.com"],
    },
    {
        "GROUP_ID": 2,
        "PARAM": ["test@mail.com"],
    },
])

connection_string = (
    f"databricks://token:{quote_plus(TOKEN)}@{DATABRICKS_HOST}?"
    f"http_path={quote_plus(DATABRICKS_HTTP_PATH)}"
    f"&catalog={quote_plus(CATALOG)}"
    f"&schema={quote_plus(SCHEMA)}"
)

engine = create_engine(connection_string, echo=True)

df.to_sql(
    "mailing_group",
    con=engine,
    index=False,
    if_exists="replace",
    dtype={
        "GROUP_ID": Integer,
        "PARAM": ARRAY(String),
    },
)
**Logs:** 
2026-08-11 08:15:07,657 INFO sqlalchemy.engine.Engine 
CREATE TABLE mailing_group (
	`GROUP_ID` INT, 
	`PARAM` ARRAY<STRING>
) USING DELTA
TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'enabled')
2026-08-11 08:15:07,657 INFO sqlalchemy.engine.Engine [no key 0.00074s] {}
2026-08-11 08:15:09,665 INFO sqlalchemy.engine.Engine INSERT INTO mailing_group (`GROUP_ID`, `PARAM`) VALUES (:`GROUP_ID`, :`PARAM`)
2026-08-11 08:15:09,666 INFO sqlalchemy.engine.Engine [generated in 0.00110s] [{'GROUP_ID': 1, 'PARAM': ['abc@mail.com', 'xyz@mail.com']}, {'GROUP_ID': 2, 'PARAM': ['test@mail.com']}]''

**Environment**
1. Python : 3.12
2. Pandas : 2.2.3
3. databricks-sqlalchemy : 2.0.10 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions