#!/usr/bin/env python3 """opening_balances テーブルのデータ確認スクリプト(簡易版)""" import subprocess import sys print("="*60) print("【opening_balances テーブルデータ確認】") print("="*60) # 簡易的な SQL クエリをpsqlで実行 queries = [ "SELECT COUNT(*) FROM opening_balances;", "SELECT fiscal_year, COUNT(*) as cnt FROM opening_balances GROUP BY fiscal_year;", "SELECT account_code, account_name, opening_debit, opening_credit FROM opening_balances WHERE fiscal_year = 2025 LIMIT 5;" ] for query in queries: print(f"\n📋 実行: {query}") try: # psql で直接実行 result = subprocess.run( ['psql', '-h', 'localhost', '-U', 'postgres', '-d', 'accounting', '-c', query], env={'PGPASSWORD': 'postgres'}, capture_output=True, text=True, timeout=5 ) if result.returncode == 0: print(result.stdout) else: print(f"❌ エラー: {result.stderr}") except subprocess.TimeoutExpired: print("⏱️ タイムアウト") except Exception as e: print(f"❌ エラー: {e}") print("\n" + "="*60)