Bug report #1417

Unable to add a Postgis layer when the key attribut have an alias

Added by mgrizonnet - almost 11 years ago. Updated over 10 years ago.

Status:Closed
Priority:Low
Assignee:nobody -
Category:Data Provider
Affected QGIS version: Regression?:No
Operating System:Windows Easy fix?:No
Pull Request or Patch supplied: Resolution:duplicate
Crashes QGIS or corrupts data: Copied to github as #:11477

Description

I created 2 views VIEW _VIEW0 and VIEW _VIEW1 in PostgreSQL.

The code:

CREATE OR REPLACE VIEW _VIEW0 AS
SELECT 
t1.geom, 
t1.id
FROM table1 t1 
ORDER BY t1.id;
CREATE OR REPLACE VIEW _VIEW0 AS
SELECT 
t1.geom, 
t1.id as id_geo
FROM table1 t1 
ORDER BY t1.id;

It is the same views. The only difference is that the attribute "id" has got an "alias" (the alias is "id_geo").
The data type of id is int4 and it is a primary key (needed by QGIS to make the connection).

The first view works well but not the second. The message returned by QGIS is that the attribute "id" is not a primary key (data not unique).

But it is the same views!!!!

History

#1 Updated by Paolo Cavallini over 10 years ago

See also #1545 (now closed as it's a duplicate)

#2 Updated by Paolo Cavallini over 10 years ago

Just tested with:

mipi=> create view view1 as select cat, the_geom from fix where cat=2531;
CREATE VIEW
mipi=> create view view2 as select cat as id, the_geom from fix where cat=2531;
CREATE VIEW

and QGIS can load both layers without hassle: can you please check again and report back?

#3 Updated by Paolo Cavallini over 10 years ago

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

Probably a duplicate of #1718

Also available in: Atom PDF