<div dir="ltr"><div><div><div><div><div>Hi,<br></div>Raymond, you can use the row_number function to add a primary key to your view.<br></div>Something like :<br></div>CREATE OR REPLACE view myview as <br>SELECT row_number () over ()::integer as id, fieldA, Field ...<br></div>from mytable .....<br></div>will add an unique integer field _id_ to your view. And this one can be used in QGIS as primary key<br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-03-26 11:15 GMT+01:00 Raymond Nijssen <span dir="ltr"><<a href="mailto:r.nijssen@terglobo.nl" target="_blank">r.nijssen@terglobo.nl</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks Bernhard. I just figured that. But my layer is not a table, it is a view. And it seems that PostgreSQL cannot have constraints on views.<br>
<br>
So, I think I just need to carefully select the right key field when loading it.<br>
<br>
(And maybe QGIS could be slightly smarter by not suggesting a boolean field by default?)<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On 26-03-15 11:07, Bernhard Ströbl wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Raymond,<br>
<br>
Am 26.03.2015 10:57, schrieb Raymond Nijssen:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks Regis, that was exactly the issue. The (boolean!) field<br>
'inonderzoek' was used as a key. When I change that to 'gid' in the Add<br>
PostGIS Table dialog, everything works correctly.<br>
<br>
Can anyone tell me why QGIS picks that boolean field for most of my<br>
tables? Can I change that behaviour by changing my database structure?<br>
</blockquote>
<br>
Maybe I can, but I would need the table definition statement for it. Can<br>
you post it here.<br>
Generally speaking you should define an integer field (use bigint if you<br>
expect _many_ datasets) as primary key for the table like:<br>
<br>
CREATE TABLE my_points<br>
(<br>
   gid integer NOT NULL,<br>
   the_geom geometry(Point,my_srid),<br>
   other_fields,<br>
   CONSTRAINT my_points_pkey PRIMARY KEY (gid)<br>
);<br>
<br>
Bernhard<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<a href="http://terglobo.nl/downloads/qgis_add_postgis_table_wrong_key.png" target="_blank">http://terglobo.nl/downloads/<u></u>qgis_add_postgis_table_wrong_<u></u>key.png</a><br>
<br>
And how can the identify results be correct anyway?<br>
<br>
Tnx,<br>
Raymond<br>
<br>
<br>
dbname='bag' host=localhost port=5432 user='postgres' sslmode=disable<br>
key='inonderzoek' estimatedmetadata=true srid=28992 type=POLYGON<br>
table="bagactueel"."<u></u>pandactueelbestaand" (geovlak) sql=<br>
<br>
<br>
<br>
On 26-03-15 10:34, Régis Haubourg wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi, I have seen such troubles when the choosen primary key from qgis<br>
side is<br>
not unique .<br>
<br>
Symptoms: selecting one feature select severals unrelated features of<br>
the<br>
same layer. relation with attributes is broken also.<br>
<br>
Can you check in your layer's definition (general tab of layer<br>
properties)<br>
if you choose gid field as key, and check if it is really unique in<br>
postgis?<br>
<br>
Cheers<br>
Régis<br>
<br>
<br>
<br>
--<br>
View this message in context:<br>
<a href="http://osgeo-org.1560.x6.nabble.com/wrong-attribute-values-for-postgis-data-in-Feature-attribute-form-tp5195518p5195523.html" target="_blank">http://osgeo-org.1560.x6.<u></u>nabble.com/wrong-attribute-<u></u>values-for-postgis-data-in-<u></u>Feature-attribute-form-<u></u>tp5195518p5195523.html</a><br>
<br>
<br>
Sent from the Quantum GIS - Developer mailing list archive at<br>
Nabble.com.<br>
______________________________<u></u>_________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/<u></u>mailman/listinfo/qgis-<u></u>developer</a><br>
<br>
</blockquote>
<br>
</blockquote>
<br>
<br>
<br>
__________ Information from ESET Mail Security, version of virus<br>
signature database 11379 (20150326) __________<br>
<br>
The message was checked by ESET Mail Security.<br>
<a href="http://www.eset.com" target="_blank">http://www.eset.com</a><br>
<br>
<br>
______________________________<u></u>_________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/<u></u>mailman/listinfo/qgis-<u></u>developer</a><br>
</blockquote>
<br></div></div><span class="im HOEnZb">
-- <br>
Terglobo<br>
Ampèrestraat 110<br>
5223 CT 's-Hertogenbosch<br>
<a href="tel:06-25314983" value="+33625314983" target="_blank">06-25314983</a><br></span><div class="HOEnZb"><div class="h5">
______________________________<u></u>_________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/<u></u>mailman/listinfo/qgis-<u></u>developer</a></div></div></blockquote></div><br></div>