How to insert arrays into ARRAY<STRING> columns using native parameters?

Open
#694 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python, sql
Domain
databases

Research direction

Start with the named-parameter usage example in docs/parameters.md and reproduce insert_test() using the supplied table definition, connector versions, and data. Check the SQL Warehouse query history to compare the bound categories value with the expected string array; done means the inserted row contains both category values rather than [].

Written by the indexing model from the issue text.

Description

Hi!

I am trying to insert an string array into a table with an ARRAY column, but it doesn't seem to register my Python string list.

CREATE TABLE prod_catalog.eu_projects.project_export (project_id bigint, categories ARRAY<STRING>);
def insert_test():
    data = {
        "project_id": 123456,
        "categories": [
            "Public Sector",
            "Healthcare",
        ],
    }
    with get_databricks_connection() as connection:
        cursor = connection.cursor()
        cursor.execute(
            "INSERT INTO prod_catalog.eu_projects.project_export(project_id, categories) VALUES (:project_id, Array(:categories))",
            data
        )
        print("Test insert completed.")

This ends up as an empty array. If I check query history on the SQL Warehouse, it says that categories was an empty array []

I have tried to read the documentation, but it is very confusing.

I am using the following versions
Python 3.13.7
databricks-sql-connector==4.1.3
databricks-sdk==0.66.0

Dominant language
Python
Stars
233
Forks
152
Avg merge
21h 5m
Merged PRs (30d)
10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from databricks/databricks-sql-python

All issues in databricks/databricks-sql-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.