[Qgis-user] QGis and Character Primary Key

Mike Toews mwtoews at gmail.com
Tue Feb 9 07:32:57 PST 2010


On 9 February 2010 01:24, F T <oukile at gmail.com> wrote:
> It is annoying for us that QGis can't use existing character primary key...
> We have to add an artificial integer primary key and transform the existing
> character primary key as a unique non null constraint.

When I was learning PostGIS, this threw me off too.

> This change is ok if you only use QGis.
> But if the data are used by an other soft that was used do deal with this
> character primary key, this cause an interoperability problem.

Can you cite any particular database issues or software where this is
a problem? Many other GIS software, including QGIS, expect to have a
single integer primary key. If you've ever used ESRI's software, you
may have also noticed FID in shapefiles and ObjectID in geodatabases.
These are integer primary keys too, it is predominantly common to have
this.

Having an extra integer column shouldn't cause any problem to a
database, since you can always make a unique key on your character
field (and use that like a primary key elsewhere for foreign keys,
etc.). Make sure your integer key uses the "serial" type, so it
auto-increments and is self-maintained. This shouldn't limit your
database design in any way.

You can hide the attribute in QGIS 1.3(?) by going to the layer
properties > attributes, and changing the edit widget to "hidden".

-Mike



More information about the Qgis-user mailing list