Use '%sql' inside a python cmd cell?

pjp94
Contributor

Hi so I want to essentially execute a sql query if a condition is met. So one of my cells in my python notebook is a sql query (%sql followed by the query). Is there any way to put that in an 'IF' statement ie if an environment variable = some value, run this query?

Hubert-Dudek
Databricks MVP

in python cell just use:

query = "SELECT 1"

spark.sql(query)


My blog: https://databrickster.medium.com/