Bug report #9803

QGIS fails to load postgis spatial views (primary key problem)

Added by Alexandre Neto over 6 years ago. Updated about 6 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Data Provider/PostGIS
Affected QGIS version:2.2.0 Regression?:No
Operating System:Windows 7 64 bit Easy fix?:No
Pull Request or Patch supplied:No Resolution:worksforme
Crashes QGIS or corrupts data:No Copied to github as #:18342

Description

Since QGIS 2.2, adding a postgis spatial view using the browser throws the following error:

"The layer dbname='postgis' host=192.168.100.7 port=5432 user='postgres' password='postgres' sslmode=disable key='cadeado' srid=3763 type=POINT table="PGHP"."infra_portoes" (geom) sql= is not a valid layer and can not be added to the map"

Adding the spatial view using the "add postgis layer", the layer is added but with the wrong primary key, resulting in odd behaviors. Selecting a good primary key in the primary key column, solves the problem.

Using DB Manager (add layer to canvas), QGIS successfully identifies the a possible primary key and everything goes well.

Despite Jürgen's opinion1, IMHO this situation is not optimal, breaks the browser usability and can be considered a step back. Obviously, I do not know if there are any other technical implications to this.

[1]

History

#1 Updated by Jürgen Fischer over 6 years ago

  • Category changed from Data Provider to Data Provider/PostGIS

#2 Updated by Alexandre Neto about 6 years ago

Doing some fast testing to see if I can close any of my bug reports, it looks like QGIS master solves this issue. Add Postgis layer and add layer by right clicking in the Browser seams to work.

On the other hand, trying to open a Spatial View by right clicking in the DB Manager fails, giving the following errors in the Log:

"No key field view given."
"PostgreSQL layer has no primary key"

And as I stated before this was working in QGIS 2.2.

#3 Updated by Giovanni Manghi about 6 years ago

  • Resolution set to worksforme
  • Status changed from Open to Closed

Also available in: Atom PDF