<div dir="ltr">Hi !<div><br></div><div>I love the "query layer" feature !</div><div><br></div><div>But there's something which makes it unusable : as soon as it returns an empty result set (which is absolutely valid), it is considered as a "bad layer" upon file opening, and the layer is destroyed.</div>

<div><br></div><div>When working with spatialite, it triggers the "handle bad layers dialog", which unfortunately is of no help.</div><div>When working with postgis, it shortly displays a message in the message bar, which I sometimes miss, and I also loose my layers.</div>

<div><br></div><div><br></div><div>Here's what I found so far :</div><div><br></div><div>- when "filtering" a regular spatialite/postgis layer, if the filter filters out every feature, the layer is still valid. (works as expected)</div>

<div>- when a query layer returns an empty result set, the layer is considered bad (unexpected).</div><div>- when a query layer returns an non-empty result set, but the query layer is filtered, the layer is considered bad (unexpected).</div>

<div>- empty views work well, filtered or not (works as expected)</div><div><br></div><div>So, views are a kind of workaround, but depending on the needs (for example if you need to change your query very often), it's not really usable either, because it's much longer to setup and it pollutes the database.</div>

<div><br></div><div><br></div><div>Does anyone have a workaround for this ? Why does QGIS have to consider empty query layers as invalid, while they work perfectly well (as long as you don't reopen the file) ?</div><div>

<br></div><div><br></div><div>I would definitely create a blocker issue for this (there are already linked issues, see below, but it seems they aren't considered as blockers) : it leads to loosing query layers very easily (and almost silently for postgis). It would be great if this could be fixed for 2.4 !</div>

<div><br></div><div>Thanks for reading !</div><div><br></div><div>Olivier</div><div><br></div><div><br></div><div>PS1 A test setup :</div><div><div><a href="https://www.dropbox.com/sh/6jar5134pvqjbjj/AADx9WoUqh3CAAyKQoMAekXla">https://www.dropbox.com/sh/6jar5134pvqjbjj/AADx9WoUqh3CAAyKQoMAekXla</a><br>

</div><div><br></div><div>PS2 Some related issues on the tracker :</div><div><a href="http://hub.qgis.org/issues/7039">http://hub.qgis.org/issues/7039</a> (about using message bar for bad layers)<br></div><div><a href="http://hub.qgis.org/issues/9708">http://hub.qgis.org/issues/9708</a> (WMS bad layers have similar problems)<br>

</div><div><a href="http://hub.qgis.org/issues/9743">http://hub.qgis.org/issues/9743</a> (Oracle bad layers have similar problems)<br></div><div><a href="http://hub.qgis.org/issues/8718">http://hub.qgis.org/issues/8718</a> (feature request which asks for solving this)</div>

</div><div><br></div><div><br></div><div><br></div></div>