How to write FOR loop in Python Impala?

I am trying to write a script to list all tables in all databases in impala using python. I am getting stuck at for loop section.

for i in databases.db:
    cur.execute("show tables in", &i)   #error occurs here
    output11 = pd.DataFrame(cur.fetchall())
    print(output11)

Since impala syntax is SHOW TABLES IN DATABASE_NAME The issue is same for HIVE.

1 answer

  • answered 2019-12-14 12:23 Sai Astro

    for i in databases.db:
        q1="show tables in "
        q2=q1+i
        cur.execute(q2)  #error occurs here
        output11 = pd.DataFrame(cur.fetchall())
    

    I found the answer. Thanks for viewing.