cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

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 ?

5 REPLIES 5

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
New Contributor III
New Contributor III

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

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.

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.