Skip to content

Instantly share code, notes, and snippets.

@swateek
Created June 18, 2025 04:02
Show Gist options
  • Save swateek/8b9238a1ebd55ff8eae9c019995864f2 to your computer and use it in GitHub Desktop.
Save swateek/8b9238a1ebd55ff8eae9c019995864f2 to your computer and use it in GitHub Desktop.
DataBricks SQL WareHouse
from databricks import sql
DATABRICKS_USE2_PAT = ""
use2_workspace = sql.connect(
server_hostname="<YOUR-SERVER-HOSTNAME>",
http_path="<YOUR-HTTP-PATH>",
access_token=DATABRICKS_USE2_PAT,
catalog="<YOUR-CATALOG-NAME>",
schema="<YOUR-SCHEMA-NAME>"
)
cursor = use2_workspace.cursor()
# cursor.execute("SELECT * from range(10)")
cursor.execute("SELECT COUNT(*) FROM view_transactions;")
print(cursor.fetchall())
cursor.close()
use2_workspace.close()
# catalog & schema are optional parameters in sql.connect()
# if not provided in connection, then the query must be written as below
# SELECT COUNT(*) FROM `catalog`.`schema`.view_transactions;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment