[Qgis-user] Composed Key: More details
Pierre Chevalier Géologue
pierrechevaliergeol at free.fr
Fri Jan 21 05:28:27 PST 2011
Hello,
Joaquim Condeça claviota:
> A composed Primary Key is a key composed by two (or more) columns.
Yes, I also often have such cases.
> I'll try to explain with an exanple:
>
> I have a country with different regions and sub-regions. Sometimes,
> these regions are changed. The geometry is different everytime I have
> a new version.
>
> The PK for one region is the column with the RegionID and the version ID.
>
> ...
>
> Any subregion must connect to the region, considering both columns as
> PK, the region and the version. Somewhere in time that subregion was
> linked to one region and then moved to another region and I must keep
> track of those changes.
>
> With this scenario, I can't connect this table to QGIS.
>
If you add a serial field to your table, as I mentioned in my last post,
it should do the trick.
The value of, say, numauto field will be automatically incremented as
your table evolves. So no more need to define primary keys.
Another idea: why not using a combination of your two keys to generate,
through a view, a primary key?
Example: I suppose your table is named toto, and your fields are named
region and version, and that version is < 999.
CREATE VIEW toto_forqgis AS
SELECT *, (region*1000 + version)::integer AS region_version
FROM toto;
Now, will qgis be fooled by this combination? I am not sure.
A+
Pierre
--
____________________________________________________________________________
Pierre Chevalier Géologue EI
Mesté Duran
32100 Condom
Tél+fax : 09 75 27 45 62
05 62 28 06 83
06 37 80 33 64
Émail : pierrechevaliergeolCHEZfree.fr
icq# : 10432285
skype : pierre.chevalier1967
http://pierremariechevalier.free.fr/pierre_chevalier_geologue
____________________________________________________________________________
More information about the Qgis-user
mailing list