#!/usr/bin/env python3 """opening_balances テーブルのデータ確認""" import psycopg try: conn = psycopg.connect('host=localhost user=postgres password=postgres dbname=accounting') cur = conn.cursor() # opening_balances テーブルの行数確認 cur.execute("SELECT COUNT(*) FROM opening_balances") count = cur.fetchone()[0] print(f"【opening_balances テーブル行数】: {count}") if count == 0: print("\n⚠️ opening_balances テーブルは空です") print("→ 期首残高データが入力されていません") else: # 年度別データを確認 cur.execute("SELECT fiscal_year, COUNT(*) as cnt FROM opening_balances GROUP BY fiscal_year ORDER BY fiscal_year") print("\n【年度別件数】") for row in cur.fetchall(): print(f" {row[0]}年度: {row[1]}件") # 2025年度のサンプルデータ print("\n【2025年度のサンプル(最初の5件)】") cur.execute(""" SELECT account_id, opening_debit, opening_credit FROM opening_balances WHERE fiscal_year = 2025 LIMIT 5 """) for row in cur.fetchall(): print(f" account_id={row[0]}, debit={row[1]}, credit={row[2]}") cur.close() conn.close() except Exception as e: print(f"❌ エラー: {e}")