""" 檢查資料庫中的觸發器 """ import psycopg2 conn = psycopg2.connect( host="10.1.0.20", port=5433, database="hr_portal", user="admin", password="DC1qaz2wsx" ) cur = conn.cursor() # 查詢所有觸發器 cur.execute(""" SELECT trigger_name, event_object_table, action_statement FROM information_schema.triggers WHERE trigger_schema = 'public' ORDER BY event_object_table, trigger_name; """) triggers = cur.fetchall() print("=== Database Triggers ===\n") if triggers: current_table = None for trig in triggers: if trig[1] != current_table: if current_table is not None: print() print(f"[{trig[1]}]") current_table = trig[1] print(f" Trigger: {trig[0]}") print(f" Action: {trig[2][:80]}...") print() else: print("No triggers found") cur.close() conn.close()