1
votes

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.

1
You might have better luck on gis.stackexchange.com for questions on how to use GIS. - mkirk

1 Answers

4
votes

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