简体   繁体   中英

Get table names from POSTGIS database with PyQGIS

How can I access the table names inside a POSTGIS database with PyQGIS? I am trying to load a layer from A POSTGIS database. I can do it if I know the table's name which I am gonna use.

If you want list of tables name from current database.

from PyQt4.QtSql import *
    db = QSqlDatabase.addDatabase("QPSQL");
    db.setHostName("localhost");
    db.setDatabaseName("postgres");
    db.setUserName("postgres");
    db.setPassword("postgres");
    db.open();
    names=db.tables( QSql.Tables)
    print names

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM