[Qgis-user] Very long sql in postgres layer definition

Samuel Ingarfield sam at sjfi.net
Thu May 26 00:33:44 PDT 2016


Hi All,

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?

There is an unanswered question on stackexchange regarding this:
http://gis.stackexchange.com/questions/162409/how-to-load-layers-from-postgres-using-select-statement

My python code is very simple:
sql = 'a very long query'
uri=QgsDataSourceURI()
uri.setConnection(host,"5432",dbname,user,passwd)
uri.setDataSource("",sql,"geom","","r.id")
vlayer = QgsVectorLayer(uri.uri(),"layer_name","postgres")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)

The debug log shows the following:
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..."
qgsmessagelog.cpp(45) : (QgsMessageLog::logMessage) [1ms]
2016-05-26T15:16:14 PostGIS[1] Erroneous query: ...etc

Any help would be great.
Sam.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20160526/116b2e6c/attachment.html>


More information about the Qgis-user mailing list