import psycopg2 from collections import defaultdict conn = psycopg2.connect('postgresql://local-Python:Neo-local-1991125@100.64.0.4:5432/LLZQ-test') cur = conn.cursor() cur.execute("SELECT table_name, column_name, data_type, ordinal_position FROM information_schema.columns WHERE table_schema = 'billiards_dwd' ORDER BY table_name, ordinal_position") results = cur.fetchall() tables = defaultdict(list) for row in results: tables[row[0]].append((row[1], row[2], row[3])) for table in sorted(tables.keys()): print(f'\n琛ㄥ悕: {table}') cols = tables[table] for col, dtype, pos in cols: print(f' {pos}. {col} ({dtype})') cur.close() conn.close()