[Qgis-user] unique id in postgis view

Giuseppe Sucameli brush.tyler at gmail.com
Mon Jun 18 15:19:04 PDT 2012


Hi,

On Mon, Jun 18, 2012 at 8:47 AM, Bernhard Ströbl
<bernhard.stroebl at jena.de> wrote:
> AFAIK QGIS needs a field which is defined as primary key field in one of the
> tables contained in the view. If this is the case the values in the field
> must be unique, too.

it depends on the QGis version you're using:

QGis < 1.8 needs a field with a unique constraint defined on it, so
a primary key or unique field for one of the tables used in the view,

in QGis >= 1.8 you should be able to choose any integer/serial or oid
field, this because being a primary key for one of the tables used in a
view doesn't mean to have unique values for the whole view.

Regards.

>
> Bernhard
>
> Am 18.06.2012 04:17, schrieb Richard Greenwood:
>
>> QGIS wants a unique id on postgis layers, so I created a view that
>> includes:
>>
>>    ROW_NUMBER() OVER (ORDER BY mytable.ogc_fid ASC) AS row_num,
>>
>> which seems to be a standard way to create a unique id on a view [1]
>> but QGIS does not "see" the row_num, i.e. it is not listed in the "No
>> Suitable Key Column" dialog box that lists the columns in the view and
>> explains why each is unsuitable.
>>
>> What am I doing wrong?
>>
>> Thanks,
>> Rich
>>
>>
>> [1]
>> http://gis.stackexchange.com/questions/12233/in-postgis-is-it-possible-to-create-a-view-with-a-unique-id

-- 
Giuseppe Sucameli



More information about the Qgis-user mailing list