ZhangZhihui's Blog  

 适用于GreenPlum, GaussDB, PostgreSQL:

import psycopg2

conn = psycopg2.connect(
    dbname="your_db",
    user="your_user",
    password="your_password",
    host="your_host",
    port="5432"
)
cur = conn.cursor()

cur.execute("""
    SELECT column_name, data_type
    FROM information_schema.columns
    WHERE table_schema = 'public' AND table_name = 'your_table'
    ORDER BY ordinal_position;
""")

for name, dtype in cur.fetchall():
    print(name, dtype)

cur.close()
conn.close()

 

posted on 2025-09-28 09:08  ZhangZhihuiAAA  阅读(9)  评论(0)    收藏  举报