How to do python within sql query in Databricks ?

Yagao
New Contributor

Can anyone show me one use case how to do python within sql query ?

Anonymous
Not applicable

Did you get any solution? My Nordstrom Employee Portal

Anonymous
Not applicable

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!

Dicer
Valued Contributor
spark.sql("select <Your Coumn> from <Your Table> ")
 

tomasz
Databricks Employee
Databricks Employee

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

jose_gonzalez
Databricks Employee
Databricks Employee

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.