How can I add a PostGIS layer to QGIS via the Python Console?
With some server setups, especially with a large number of tables, it can be very slow to load the list of layers via the Browser or Data Source Manager.
pyqgispythonqgisqgis-2qgis-3
How can I add a PostGIS layer to QGIS via the Python Console?
With some server setups, especially with a large number of tables, it can be very slow to load the list of layers via the Browser or Data Source Manager.
Best Answer
Here are code snippets to add a layer.
I put table name in a variable since it's used twice and the geometry column because that's what I most often change.
QGIS 3.x
QGIS 2.x