check_columns.py 588 B

12345678910111213141516171819202122232425262728
  1. """Check table columns"""
  2. import psycopg2
  3. conn = psycopg2.connect(
  4. host="192.168.3.143",
  5. port=5432,
  6. database="dataops",
  7. user="postgres",
  8. password="dataOps",
  9. )
  10. cur = conn.cursor()
  11. tables = ["test_sales_data", "test_user_statistics", "test_product_inventory"]
  12. for table in tables:
  13. cur.execute(
  14. """
  15. SELECT column_name FROM information_schema.columns
  16. WHERE table_name = %s ORDER BY ordinal_position
  17. """,
  18. (table,),
  19. )
  20. columns = [r[0] for r in cur.fetchall()]
  21. print(f"{table}: {columns}")
  22. cur.close()
  23. conn.close()