pythonsqldatabricksmulti-query

Databricks SQL Connector for Python - How to execute Multiple Queries?


I can successfully execute each query individually, and can run multiple in the databricks environment, However I can not get it to work for a multi-query statement through Databricks SQL Connector for Python. Piece of the python below;

query = '''
Drop table if exists Table_Name

create table Table_Name (
Field1 String,
Field2 Int
 )
 '''
cursor.execute(query)

Which will give the following error;

mismatched input 'create' expecting

Are Multi-query statements possible, if so what am I missing?


Solution

  • missing ; after each statement maybe?

    query1 = '''Drop table if exists Table_Name; '''
    query2= '''
    create table Table_Name (
    Field1 String,
    Field2 Int
     );
     '''
    cursor.execute(query1)
    cursor.execute(query2)