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

Junior Delaz delazj at gmail.com
Thu Mar 26 03:26:25 PDT 2015


Hi,
Raymond, you can use the row_number function to add a primary key to your
view.
Something like :
CREATE OR REPLACE view myview as
SELECT row_number () over ()::integer as id, fieldA, Field ...
from mytable .....
will add an unique integer field _id_ to your view. And this one can be
used in QGIS as primary key

2015-03-26 11:15 GMT+01:00 Raymond Nijssen <r.nijssen at terglobo.nl>:

> 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
>>
>
> --
> Terglobo
> Ampèrestraat 110
> 5223 CT 's-Hertogenbosch
> 06-25314983
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150326/9fef0bcd/attachment.html>


More information about the Qgis-developer mailing list