I am having trouble adding the results of spatial queries against a PostGIS connection to the map canvas in QGIS.


  • I am able to add the results of queries against my PostgreSQL/PostGIS connection -- as long as the queries do not contain any spatial statements (e.g. ST_Union, ST_Buffer, etc.)
  • The "Execute SQL" dialog DOES return the correct results of the spatial query but when I load the layer to the map, there is an error ("Unavailable layer")
  • QGIS version = 3.30.3
  • PostGIS_version() = 3.2 USE_GEOS=1 USE_PROJ=1 USE_STATS=1

I've already tried making sure to include a unique key column in my query - as I thought that maybe it would be a requirement for the layer to display. This is my query:

SELECT 1 as id, ST_Union(ST_Buffer(1609*20))
FROM highways
WHERE name = 'US Route 1' AND state = 'MD';

This is what the added QueryLayer looks like when I attempt to add it:

screenshot of QGIS Layers panel showing issue with adding the query result to the map

1 Answer 1


Nevermind - it seemed that the QGIS query interface does not like the trailing ;.

Removing the semi-colon seems to resolve the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.