2012-02-15 100 views

回答

2

我不知道的Postgres,但使用MySQLdb的你总是可以使用以下方法:

cursor.execute("select database()") 
db_name = cursor.fetchone()[0] 

也许有一个更清洁的方式做到这一点...

编辑:

其他信息取决于你在找什么,但是例如拿到表名称

cursor.execute("show tables") 
for r in cursor.fetchall(): 
    print r[0] 

还有很多其他功能可用...有什么具体的你要找的?

+0

如果游标连接到PostgreSQL,那么这两个都不会起作用。 – 2012-02-15 15:49:35

+0

是的,我知道......正如我所说我对PostgreSQL不太了解。我总是可以使用一些东西,如'SELECT table_name FROM information_schema.tables'。但我不知道任何其他方式直接从光标获得这种信息:(。 – t00ny 2012-02-15 15:54:31

+0

@ t00ny谢谢你的答案哥们!我想出了一个postgres同样'cursor_postgres.execute(“select current_database()”) ' – jerrymouse 2012-02-15 19:16:58