I've tried to add my temporary table into QGIS canvas using pyqgis but it's failed. Here the code(view_tatanga
is a temporary table that I've created using sql on pgadmin) :
uri = QgsDataSourceURI()
sql = "SELECT * FROM gis.view_tatanga"
uri.setConnection("localhost", "5433", "db_pbb", "postgres", "septin")
uri.setDataSource('', u'(%s\n)' % sql, 'geom', '', 'nop')
#uri.setDataSource("",sql,"geom","","nop")
tmadminkec = QgsVectorLayer(uri.uri(), 'view_tatanga', "postgres")
QgsMapLayerRegistry.instance().addMapLayer(tmadminkec)
I didn't get any error when I try to load a usual table (non temporary table). Any ideas ?
uri.setDataSource('gis', 'view_tatanga', 'geom', '', 'nop')
Note thatnop
must be a field with unique values.