title: How to extract table names and column names from sql query?
body: <p>So let assume we have such simple query:</p>
  
  <pre><code>Select a.col1, b.col2 from tb1 as a inner join tb2 as b on tb1.col7 = tb2.col8;
  </code></pre>
  
  <p>The result should  looks this way:</p>
  
  <pre><code>tb1 col1
  tb1 col7
  tb2 col2
  tb2 col8
  </code></pre>
  
  <p>I've tried to solve this problem using some python library:</p>
  
  <p>1) Even extracting only tables using <code>sqlparse</code> might be a huge problem. For example <a href="https://github.com/andialbrecht/sqlparse/blob/master/examples/extract_table_names.py" rel="noreferrer">this</a> official book doesn't work properly at all.</p>
  
  <p>2) Using regular expression seems to be really hard to achieve.</p>
  
  <p>3) But then I found <a href="https://stackoverflow.com/questions/22976019/how-to-get-table-name-of-the-executed-query-python-sqlite">this</a> , that might help. However the problem is that I can't connect to any database and execute that query.</p>
  
  <p>Any ideas?</p>