<div dir="ltr">Hi All,<div><br></div><div>I'm trying to load a postigs layer via python which is defined by a very long sql query. It seems that Qgis is truncating the query (which obviously causes it to fail). Has anyone come across this before and come up with a solution? Or am I loading the layer incorrectly?</div><div><br></div><div>There is an unanswered question on stackexchange regarding this: <a href="http://gis.stackexchange.com/questions/162409/how-to-load-layers-from-postgres-using-select-statement">http://gis.stackexchange.com/questions/162409/how-to-load-layers-from-postgres-using-select-statement</a></div><div><br></div><div>My python code is very simple:</div><div><div>sql = 'a very long query'</div><div>uri=QgsDataSourceURI()</div><div>uri.setConnection(host,"5432",dbname,user,passwd)</div><div>uri.setDataSource("",sql,"geom","","<a href="http://r.id">r.id</a>")</div><div>vlayer = QgsVectorLayer(uri.uri(),"layer_name","postgres")</div><div>QgsMapLayerRegistry.instance().addMapLayer(vlayer)</div></div><div><br></div><div>The debug log shows the following:</div><div>qgsmessagelog.cpp(45) : (QgsMessageLog::logMessage) [1ms] 2016-05-26T15:16:14 PostGIS[1] NOTICE: NOTICE:  identifier "...long query here..." will be truncated to "...truncated query here..."<br></div><div>qgsmessagelog.cpp(45) : (QgsMessageLog::logMessage) [1ms] 2016-05-26T15:16:14 PostGIS[1] Erroneous query: ...etc<br></div><div><br></div><div>Any help would be great.</div><div>Sam.</div></div>