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
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more