0

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?

eshirvana
  • 23,227
  • 3
  • 22
  • 38
kmaclean
  • 3
  • 1

2 Answers2

0

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)
eshirvana
  • 23,227
  • 3
  • 22
  • 38
  • Ya, I am not sure why this package doesn't like ';' but i can only get the single statements to run if I drop the semicolon, and having them for multi-statements give the same error as op. Don't know if this library is limited https://pypi.org/project/databricks-sql-connector/ . Single statement semicolon error: "extraneous input ';' expecting " – kmaclean Dec 16 '21 at 05:38
  • Reading documents , it only talks about executing a command at a time. So I’m afraid you have to do them in separate commands – eshirvana Dec 16 '21 at 05:56
0

Please add semicolon after each query:

Drop table if exists Table_Name;

create table Table_Name ( Field1 String, Field2 Int );

Hubert Dudek
  • 1,666
  • 1
  • 13
  • 21
  • Ya, I am not sure why this package doesn't like ';' but i can only get the single statements to run if I drop the semicolon, and having them for multi-statements give the same error as op. Don't know if this library is limited pypi.org/project/databricks-sql-connector . Single statement semicolon error: "extraneous input ';' expecting " – kmaclean Dec 16 '21 at 05:39