Files
AestheChic/utils/remove_null_columns_under_threshold.py
T
2026-07-31 01:41:46 +02:00

39 lines
733 B
Python

import sqlite3
db = "paintingzz.db"
conn = sqlite3.connect(db)
cur = conn.cursor()
table = "inspections"
# Find completely NULL columns
cur.execute(f"PRAGMA table_info({table})")
columns = [row[1] for row in cur.fetchall()]
empty_columns = []
for col in columns:
print('cucurucu')
cur.execute(
f'SELECT COUNT(*) FROM "{table}" WHERE "{col}" IS NOT NULL'
)
count = cur.fetchone()[0]
if count <100 :
print('list b growing')
empty_columns.append(col)
print(empty_columns)
print("Removing:", empty_columns)
# SQLite >= 3.35 supports DROP COLUMN
for col in empty_columns:
cur.execute(
f'ALTER TABLE "{table}" DROP COLUMN "{col}"'
)
conn.commit()
conn.close()