René's URL Explorer Experiment


Title: How to insert into VARIANT column? · Issue #681 · databricks/databricks-sql-python · GitHub

Open Graph Title: How to insert into VARIANT column? · Issue #681 · databricks/databricks-sql-python

X Title: How to insert into VARIANT column? · Issue #681 · databricks/databricks-sql-python

Description: As we all know, Databricks has a VARIANT data type that is more performant than standard JSON strings for nested data. However, I don't understand how I am supposed to insert into such a column using databricks-sql-connector==4.0.5 thoug...

Open Graph Description: As we all know, Databricks has a VARIANT data type that is more performant than standard JSON strings for nested data. However, I don't understand how I am supposed to insert into such a column usi...

X Description: As we all know, Databricks has a VARIANT data type that is more performant than standard JSON strings for nested data. However, I don't understand how I am supposed to insert into such a column...

Opengraph URL: https://github.com/databricks/databricks-sql-python/issues/681

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to insert into VARIANT column?","articleBody":"As we all know, Databricks has a [VARIANT data type](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datatypes) that is more performant than standard JSON strings for nested data. However, I don't understand how I am supposed to insert into such a column using databricks-sql-connector==4.0.5 though.\n\nIf you want to write to a [PostgreSQL JSON column in psycopg2](https://stackoverflow.com/a/31796487), you use json dump. This trick did not seem to work here. I also tried custom escaped JSON and simply dict, but also no.\n\n```python\nimport databricks.sql\nimport json\n\n# Replace with your Databricks SQL warehouse details\nserver_hostname = \"\u003cSERVER_HOSTNAME\u003e\"\nhttp_path = \"\u003cHTTP_PATH\u003e\"\naccess_token = \"\u003cACCESS_TOKEN\u003e\"\n\n# Example data to insert\ncontent = {\n    \"age\": 29,\n    \"city\": \"New York\"\n}\ndata = [\n    (1, \"Alice\", json.dumps(content)),\n    2, \"Bob\", None), # (2, \"Bob\", data) # Raises error\n    (3, \"Charlie\", \"\"\"{\"age\": 29, \"city\": \"New York\"}\"\"\"),\n]\n\n# Connect to Databricks SQL\nwith databricks.sql.connect(\n    server_hostname=server_hostname,\n    http_path=http_path,\n    access_token=access_token\n) as connection:\n    with connection.cursor() as cursor:\n        # Insert data into Delta table\n        cursor.execute(\"CREATE OR REPLACE TABLE test_catalog.ad_hoc.variant_test (id INT, name STRING, content VARIANT) USING DELTA\")\n        cursor.executemany(\n            \"INSERT INTO prod_catalog.ad_hoc.variant_test (id, name, content) VALUES (?, ?, ?)\",\n            data\n        )\n```\n\nIf I query the resulting table,\n```sql\nSELECT *, content:age, parse_json(\"{\\\"age\\\": 29, \\\"city\\\": \\\"New York\\\"}\") FROM ad_hoc.variant_test ORDER BY id;\n```\n\n1 and 3 succeeds, but it seems to end up as a \"flat\"`STRING` (`schema_of_variant(content)`) instead of `OBJECT\u003cage: BIGINT, city: STRING\u003e`.\n\n\u003cimg width=\"815\" height=\"255\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/4bc58cfe-1a69-47d9-af25-4eb728a76c57\" /\u003e\n\nAttempt 2 (insert a dict) raises the error\n\n```databricks.sql.exc.ServerOperationError: [DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION] Cannot resolve \"content\" due to data type mismatch: cannot cast \"MAP\u003cVOID, VOID\u003e\" to \"VARIANT\". SQLSTATE: 42K09; line 1 pos 0```\n\nCould we add documentation for how this is supposed to work? I guess MAP, STRUCT and VARIANT all map to Python type dict in some sense. It is only that VARIANT don't have a predefined schema like MAP or STRUCT, and unlike MAP can be nested?","author":{"url":"https://github.com/excavator-matt","@type":"Person","name":"excavator-matt"},"datePublished":"2025-08-20T07:35:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/681/databricks-sql-python/issues/681"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:5b30ffc4-bc86-a4b6-49f7-ceeb07ad81d2
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9032:35E6BA:14ED12B:1D33B52:6970D36C
html-safe-nonce2182f50413c6dbfdc3a44d41ad955399fdb4e9f0b831997c06ad4b5e65d7c6a4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDMyOjM1RTZCQToxNEVEMTJCOjFEMzNCNTI6Njk3MEQzNkMiLCJ2aXNpdG9yX2lkIjoiNzA3MjkxOTU4ODk2OTY5ODE1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac0130b536604a306c604915233976b374a948a76b05176ba823e659907010715c
hovercard-subject-tagissue:3336933851
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/databricks/databricks-sql-python/681/issue_layout
twitter:imagehttps://avatars.githubusercontent.com/u/4998052?s=400&v=4
twitter:cardsummary
og:imagehttps://avatars.githubusercontent.com/u/4998052?s=400&v=4
og:image:altAs we all know, Databricks has a VARIANT data type that is more performant than standard JSON strings for nested data. However, I don't understand how I am supposed to insert into such a column usi...
og:site_nameGitHub
og:typeobject
og:author:usernameexcavator-matt
hostnamegithub.com
expected-hostnamegithub.com
None034aaee9edccd455c18591b13122193c6e12dc773e8a203be73abe934f3e3a72
turbo-cache-controlno-preview
go-importgithub.com/databricks/databricks-sql-python git https://github.com/databricks/databricks-sql-python.git
octolytics-dimension-user_id4998052
octolytics-dimension-user_logindatabricks
octolytics-dimension-repository_id493695132
octolytics-dimension-repository_nwodatabricks/databricks-sql-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id493695132
octolytics-dimension-repository_network_root_nwodatabricks/databricks-sql-python
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release52d1d534d0b88c64972e852deb460d09b433b8b2
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/databricks/databricks-sql-python/issues/681#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fdatabricks%2Fdatabricks-sql-python%2Fissues%2F681
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fdatabricks%2Fdatabricks-sql-python%2Fissues%2F681
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=databricks%2Fdatabricks-sql-python
Reloadhttps://patch-diff.githubusercontent.com/databricks/databricks-sql-python/issues/681
Reloadhttps://patch-diff.githubusercontent.com/databricks/databricks-sql-python/issues/681
Reloadhttps://patch-diff.githubusercontent.com/databricks/databricks-sql-python/issues/681
databricks https://patch-diff.githubusercontent.com/databricks
databricks-sql-pythonhttps://patch-diff.githubusercontent.com/databricks/databricks-sql-python
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fdatabricks%2Fdatabricks-sql-python
Fork 132 https://patch-diff.githubusercontent.com/login?return_to=%2Fdatabricks%2Fdatabricks-sql-python
Star 218 https://patch-diff.githubusercontent.com/login?return_to=%2Fdatabricks%2Fdatabricks-sql-python
Code https://patch-diff.githubusercontent.com/databricks/databricks-sql-python
Issues 85 https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/issues
Pull requests 44 https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/pulls
Actions https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/actions
Projects 0 https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/projects
Wiki https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/security
Please reload this pagehttps://patch-diff.githubusercontent.com/databricks/databricks-sql-python/issues/681
Insights https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/pulse
Code https://patch-diff.githubusercontent.com/databricks/databricks-sql-python
Issues https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/issues
Pull requests https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/pulls
Actions https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/actions
Projects https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/projects
Wiki https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/wiki
Security https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/security
Insights https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/databricks/databricks-sql-python/issues/681
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/databricks/databricks-sql-python/issues/681
How to insert into VARIANT column?https://patch-diff.githubusercontent.com/databricks/databricks-sql-python/issues/681#top
https://github.com/excavator-matt
https://github.com/excavator-matt
excavator-matthttps://github.com/excavator-matt
on Aug 20, 2025https://github.com/databricks/databricks-sql-python/issues/681#issue-3336933851
VARIANT data typehttps://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datatypes
PostgreSQL JSON column in psycopg2https://stackoverflow.com/a/31796487
https://private-user-images.githubusercontent.com/194129212/479871833-4bc58cfe-1a69-47d9-af25-4eb728a76c57.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjkwMDIxMzcsIm5iZiI6MTc2OTAwMTgzNywicGF0aCI6Ii8xOTQxMjkyMTIvNDc5ODcxODMzLTRiYzU4Y2ZlLTFhNjktNDdkOS1hZjI1LTRlYjcyOGE3NmM1Ny5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMTIxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDEyMVQxMzIzNTdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1iOGU1YmRkZjhhMjE3MmExYjMwZmU0MGE0OWEzM2MyYTM5MzFiNTYyNDdkNjdmODdiMmNmZDEyMTA0YzkwMWUxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.Fiib_G3RUpbArQJHcG8XYOv8eHYGw8z1FCWo0fzSH1w
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.