How to do python within sql query in Databricks ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2022 03:52 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 04:39 AM
Did you get any solution? My Nordstrom Employee Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 03:58 PM
Hi @Ya Gao and @Brooks foster ! It seems like maybe you two are experiencing a similar need? I would love to know more about what you are trying to solve for - please comment below! And of course if you have made any progress since you posted, definitely let us know.
In the meantime I am going to try and find a Databricks expert who has used Python in a SQL query for you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2022 09:50 AM
spark.sql("select <Your Coumn> from <Your Table> ")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2022 03:20 PM
To run Python within a SQL query you have to first define a Python function and then register it as a UDF. Once that is done you are able to call that UDF within a SQL query. Please take a look at this documentation here:
https://docs.databricks.com/spark/latest/spark-sql/udf-python.html#register-a-function-as-a-udf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2022 04:12 PM
Hi @Ya Gao,
Just a friendly follow-up. Did any of the responses help you to resolve your question? if it did, please mark it as best. Otherwise, please let us know if you still need help.

