[Qgis-developer] wrong attribute values for postgis data in Feature attribute form

Bernhard Ströbl bernhard.stroebl at jena.de
Thu Mar 26 03:26:26 PDT 2015


Hi Raymond,

I thought it might be views because I never had any problems with 
tables. When defining views you should include a field
1) that is a primary key in the table it comes from and
2) whose values are unique in the view.

example: view with _one_ owner per parcel (parcels may be included 
several times if they have more than one owner)
a) use parcel-id => not unique, won't work
b) use owner-id => will work if no owner has more than one parcel (which 
would make the owner-id unique)
c) use id of the parcel-owner-relation table => should work

you still might need to carefully choose the id field when loading it 
into QGIS

Bernhard

Am 26.03.2015 11:15, schrieb Raymond Nijssen:
> 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.
>
> So, I think I just need to carefully select the right key field when
> loading it.
>
> (And maybe QGIS could be slightly smarter by not suggesting a boolean
> field by default?)
>
>
> On 26-03-15 11:07, Bernhard Ströbl wrote:
>> Hi Raymond,
>>
>> Am 26.03.2015 10:57, schrieb Raymond Nijssen:
>>> Thanks Regis, that was exactly the issue. The (boolean!) field
>>> 'inonderzoek' was used as a key. When I change that to 'gid' in the Add
>>> PostGIS Table dialog, everything works correctly.
>>>
>>> Can anyone tell me why QGIS picks that boolean field for most of my
>>> tables? Can I change that behaviour by changing my database structure?
>>
>> Maybe I can, but I would need the table definition statement for it. Can
>> you post it here.
>> Generally speaking you should define an integer field (use bigint if you
>> expect _many_ datasets) as primary key for the table like:
>>
>> CREATE TABLE my_points
>> (
>>    gid integer NOT NULL,
>>    the_geom geometry(Point,my_srid),
>>    other_fields,
>>    CONSTRAINT my_points_pkey PRIMARY KEY (gid)
>> );
>>
>> Bernhard
>>
>>>
>>> http://terglobo.nl/downloads/qgis_add_postgis_table_wrong_key.png
>>>
>>> And how can the identify results be correct anyway?
>>>
>>> Tnx,
>>> Raymond
>>>
>>>
>>> dbname='bag' host=localhost port=5432 user='postgres' sslmode=disable
>>> key='inonderzoek' estimatedmetadata=true srid=28992 type=POLYGON
>>> table="bagactueel"."pandactueelbestaand" (geovlak) sql=
>>>
>>>
>>>
>>> On 26-03-15 10:34, Régis Haubourg wrote:
>>>> Hi, I have seen such troubles when the choosen primary key from qgis
>>>> side is
>>>> not unique .
>>>>
>>>> Symptoms: selecting one feature select severals unrelated features of
>>>> the
>>>> same layer. relation with attributes is broken also.
>>>>
>>>> Can you check in your layer's definition (general tab of layer
>>>> properties)
>>>> if you choose gid field as key, and check if it is really unique in
>>>> postgis?
>>>>
>>>> Cheers
>>>> Régis
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://osgeo-org.1560.x6.nabble.com/wrong-attribute-values-for-postgis-data-in-Feature-attribute-form-tp5195518p5195523.html
>>>>
>>>>
>>>>
>>>> Sent from the Quantum GIS - Developer mailing list archive at
>>>> Nabble.com.
>>>> _______________________________________________
>>>> Qgis-developer mailing list
>>>> Qgis-developer at lists.osgeo.org
>>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>>
>>>
>>
>>
>>
>> __________ Information from ESET Mail Security, version of virus
>> signature database 11379 (20150326) __________
>>
>> The message was checked by ESET Mail Security.
>> http://www.eset.com
>>
>>
>> _______________________________________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>


__________ Information from ESET Mail Security, version of virus signature database 11379 (20150326) __________

The message was checked by ESET Mail Security.
http://www.eset.com




More information about the Qgis-developer mailing list