How do I get tables in postgres using psycopg2?

后端 未结 5 547
再見小時候
再見小時候 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:28

    This did the trick for me:

    cursor.execute("""SELECT table_name FROM information_schema.tables
           WHERE table_schema = 'public'""")
    for table in cursor.fetchall():
        print(table)
    

提交回复
热议问题