def extract_tables(sql):
 parsed = sqlparse.parse(sql)
 if (not parsed):
  return ()
 insert_stmt = (parsed[0].token_first().value.lower() == 'insert')
 stream = extract_from_part(parsed[0], stop_at_punctuation=insert_stmt)
 identifiers = extract_table_identifiers(stream, allow_functions=(not insert_stmt))
 return tuple((i for i in identifiers if i.name))

def extract_tables ( sql ) : parsed = sqlparse . parse ( sql ) if ( not parsed ) : return ( ) insert_stmt = ( parsed [ 0 ] . token_first ( ) . value . lower ( ) == 'insert' ) stream = extract_from_part ( parsed [ 0 ] , stop_at_punctuation = insert_stmt ) identifiers = extract_table_identifiers ( stream , allow_functions = ( not insert_stmt ) ) return tuple ( ( i for i in identifiers if i . name ) )
extract the table names from an sql statment .