-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinspect_forecasts.py
More file actions
36 lines (28 loc) · 1.1 KB
/
inspect_forecasts.py
File metadata and controls
36 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import psycopg2
from dotenv import load_dotenv
load_dotenv()
DATABASE_URL = os.getenv("DATABASE_URL")
def inspect_tables():
try:
conn = psycopg2.connect(DATABASE_URL)
cur = conn.cursor()
cur.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';")
tables = cur.fetchall()
print("Tables:", [t[0] for t in tables])
# Check columns for forecasts_contexts and indicators_contexts
for table in ['forecasts_contexts', 'indicators_contexts']:
print(f"\nColumns in {table}:")
cur.execute(f"SELECT column_name FROM information_schema.columns WHERE table_name = '{table}';")
cols = cur.fetchall()
print([c[0] for c in cols])
# Sample data
print(f"Sample data from {table}:")
cur.execute(f"SELECT * FROM {table} ORDER BY created_at DESC LIMIT 1;")
row = cur.fetchone()
print(row)
conn.close()
except Exception as e:
print(e)
if __name__ == "__main__":
inspect_tables()