I would like to list the names of all schemas of PostGIS in a given DB called DB-1 in PyQGIS. My attempt was inspired by : Getting table names from PostGIS database in PyQGIS
from PyQt5.QtSql import *
db = QSqlDatabase.addDatabase("QPSQL");
db.setHostName("localhost");
db.setDatabaseName("DB-1");
db.setUserName("postgres");
db.setPassword("postgres");
db.open();
names=db.schemas(QSql.Schemas)
print names
it results :
Traceback (most recent call last):
File "C:\OSGeo4W\apps\Python39\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 8, in <module>
AttributeError: 'QSqlDatabase' object has no attribute 'schemas'
I think the issues is there : names=db.schemas( QSql.Schemas)
. Is there any other attribute that could do the job?