According to geopackage.org's "Getting Started With GeoPackage" guide, features are stored in user-defined data tables. It seems like it says that these tables require a primary key:
Other than the geometry column and a primary key, the schema of a features table is up to the implementer.
(Emphasis mine)
Is that a hard requirement? The underlying SQLite probably doesn't require a primary key, but does the GeoPackage specification mandate each layer to have one?
Motivation:
I'm asking because QGIS 3.4.4 seems to handle this inconsistently. If you intersect two vector layers the resulting layer will often not have any unique attributes (except for maybe the geometry column if the input layers were topologic).
- If I try to store the result directly to a GeoPackage layer, features that would lead to UNIQUE constraint violations on the
fid
column (which corresponds to thefid
of the first input layer and is apparently automatically chosen as the new GeoPackage layer's PK) are simply omitted, turning the resulting layer incomplete. - If I store the result in a "temporary layer", the result is complete.
fid
of the first input layer becomesfid
column of the temporary layer andfid
of the second input layer becomesfid_2
there.- If I naïvely try to persist it in a GeoPackage layer using "make permanent", that fails due to
UNIQUE
constraint violations. - If I use "make permanent" but in the dialog remove
fid
from the "FID" field, I can save to a GeoPackage layer fine. (And loading from it confirms that all the features are still there and that no new unique column for a PK has been added.)
- If I naïvely try to persist it in a GeoPackage layer using "make permanent", that fails due to
- If I start from a layer loaded from a GeoPackage which apparently has a PK (field
fid
has "Not Null" and "Unique" checked as restrictions in Layer properties > Attribute form) and in remove thefid
field in Layer properties > Source Fields, QGIS refuses to save that layer when trying to leave "editing mode" for that layer.
(Not tagging with qgis, qgis-3.4, etc., as the question itself is about the file format and should be independent of what Software is being used.)