import psycopg from read_dat import read_binary_file file_path = "lz.out/lz.rivqdown.dat" df = read_binary_file(file_path) # PostgreSQL连接配置 postgres_config = { "host": "192.168.3.12", "user": "prepare", "password": "preparepassword", "dbname": "preparedb", } postgres_conn = psycopg.connect(**postgres_config) postgres_cursor = postgres_conn.cursor() for index, row in df.iterrows(): for i in range(len(row)): postgres_cursor.execute( "INSERT INTO river_flow (river_id, created_at, runoff) VALUES (%s, %s, %s)", (i + 1, index, row[i]), ) postgres_conn.commit() postgres_cursor.close() postgres_conn.close()