build_db.py: Improve parsing of tables