I have a shapefile and a table which I import both of them to PostGIS. With pgAdminII I am able to manipulate the table, join to shapefile and calculate new fields. When I try to do that with python inside QGIS I get no success.
Example:
uri = QgsDataSourceURI() uri.setConnection("localhost", "****", "****", "postgres", "postgres") uri.setDataSource("public", "shp_name","geom", '',"gid") db = QSqlDatabase.addDatabase("QPSQL"); db.setDatabaseName(uri.database()) db.setPort(int(uri.port())) db.setUserName(uri.username()) db.setPassword(uri.password()) db.open() query = db.exec_("""SELECT* INTO new_table FROM shp_name INNER JOIN table ON shp_name.code = table.code""") query.next() I do that and it is not working. What I am doing wrong? My objective is to perform some operations with tables and in final join to initial shapefile and open in QGIS, but I am not getting success.
أكثر...
Example:
uri = QgsDataSourceURI() uri.setConnection("localhost", "****", "****", "postgres", "postgres") uri.setDataSource("public", "shp_name","geom", '',"gid") db = QSqlDatabase.addDatabase("QPSQL"); db.setDatabaseName(uri.database()) db.setPort(int(uri.port())) db.setUserName(uri.username()) db.setPassword(uri.password()) db.open() query = db.exec_("""SELECT* INTO new_table FROM shp_name INNER JOIN table ON shp_name.code = table.code""") query.next() I do that and it is not working. What I am doing wrong? My objective is to perform some operations with tables and in final join to initial shapefile and open in QGIS, but I am not getting success.
أكثر...