I am new to QGIS. I am trying to connect a view from PostGIS to QGIS (3.16.4, same with 3.12). The PostGIS connection in QGIS browser have no issues and when "Test Connection" it says it can connect.

But when I am trying to add the layer I am getting this error:

Layer is not valid: The layer dbname='dwa' host=localhost port=40802 user='user' password='user' key='"bin"' srid=4326 type=Polygon table="public"."height_grid_layer_view" (bin) is not a valid layer and can not be added to the map. Reason:

The pgAdmin 4 shows the view in Geometry Viewer without any problem with the SQL: SELECT * FROM public.height_grid_layer_view

What can I do?

enter image description here

  • 3
    Does your view have a primary key id? Feb 26, 2021 at 21:55
  • 1
    looks like your table is a binary (bin) type - for QGIS needs to be a (geom)
    – Mapperz
    Feb 26, 2021 at 22:06
  • In client/server operations the directionality is important. You want to connect from QGIS (client) to PostgreSQL (database server). PostGIS is an EXTENSION within PostgreSQL, but there is a native PG geometry type as well, so your issue seems to be that you are not using PostGIS.
    – Vince
    Feb 26, 2021 at 22:24
  • 1
    what do you get when you run \d public.height_grid_layer_view in the psql console (not in pgadmin)?
    – JGH
    Feb 26, 2021 at 23:03
  • 2
    You need a primary key, generate one if you don't have it. Mar 3, 2021 at 22:43


Your Answer

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

Browse other questions tagged or ask your own question.