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.
Asked
Active
Viewed 1,419 times
1
-
You might have better luck on http://gis.stackexchange.com/ for questions on how to use GIS. – mkirk Dec 23 '15 at 02:14
1 Answers
4
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

Fran Raga
- 624
- 7
- 20