I've tried adding a vector from Mysql table (Mysql 5.1, MyISAM) to QGIS 2.6. All columns are visible except Primary key column(s).

Could anyone confirm this behaviour? Could we consider it a bug?


I believe that GDAL is taking your primary key column and uses it as a FID which is the internal Feature ID. That is not meant to be published as a normal attribute. See the following example. The table in the Spatialite has a column OGC_FID which is selected to be used as FID and it does not appear in the attributes of the feature. The value of the OGC_FID field is used in OGRFeature(points):1

ogrinfo OSM.sqlite points
INFO: Open of `OSM.sqlite'
      using driver `SQLite' successful.

Layer name: points
Geometry: Point
Feature Count: 314281
Extent: (19.065536, 59.457619) - (31.464966, 70.089821)
Layer SRS WKT:
        SPHEROID["WGS 84",6378137,298.257223563,
FID Column = OGC_FID              <= this line shows where the FID is taken
Geometry Column = GEOMETRY
osm_id: String (0.0)
name: String (0.0)
barrier: String (0.0)
highway: String (0.0)
ref: String (0.0)
address: String (0.0)
is_in: String (0.0)
place: String (0.0)
man_made: String (0.0)
other_tags: String (0.0)

OGRFeature(points):1                <= No OGC_FID included in the attributes
  osm_id (String) = 115899
  name (String) = (null)
  barrier (String) = (null)
  highway (String) = traffic_signals
  ref (String) = (null)
  address (String) = (null)
  is_in (String) = (null)
  place (String) = (null)
  man_made (String) = (null)
  other_tags (String) = (null)
  POINT (25.7409545 66.49637)

There are workarounds. You must select the fid as a normal attribute and you can probably do it either in

  1. Database by making a view "CREATE VIEW expose AS SELECT PK_COLUMN as PK_COLUMN, PK_COLUMN AS EXPOSED PK_COLUMN ..."
  2. Read the database table through GDAL virtual vector format http://www.gdal.org/drv_vrt.html and define the PK column twice in there
  3. Use GDAL/OGR SQL support. Here is an example:
ogrinfo OSM.sqlite -sql "select ogc_fid as exposed_fid, name, geometry from points"
INFO: Open of OSM.sqlite
using driver SQLite successful.
Layer name: SELECT
Geometry: Unknown (any)
Feature Count: 314281
exposed_fid (Integer) = 1    <= OGC_FID now listed as a normal attribute
name (String) = (null)
POINT (25.7409545 66.49637)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.