Bug report #9803
QGIS fails to load postgis spatial views (primary key problem)
|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|
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.
#2 Updated by Alexandre Neto over 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.