How do I get tables in postgres using psycopg2?

后端 未结 5 541
再見小時候
再見小時候 2021-01-31 01:48

Can someone please explain how I can get the tables in the current database?

I am using postgresql-8.4 psycopg2.

5条回答
  •  野的像风
    2021-01-31 02:18

    you can use this code for python 3

    import psycopg2
    
    conn=psycopg2.connect(database="your_database",user="postgres", password="",
    host="127.0.0.1", port="5432")
    
    cur = conn.cursor()
    
    cur.execute("select * from your_table")
    rows = cur.fetchall()
    conn.close()
    

提交回复
热议问题