Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPKG's generated by sno don't have AUTOINCREMENT #188

Closed
olsen232 opened this issue Aug 4, 2020 · 1 comment
Closed

GPKG's generated by sno don't have AUTOINCREMENT #188

olsen232 opened this issue Aug 4, 2020 · 1 comment
Assignees

Comments

@olsen232
Copy link
Collaborator

olsen232 commented Aug 4, 2020

A GPKG feature table must have an INTEGER PRIMARY KEY column, and this column may be AUTOINCREMENT. Whether it is AUTOINCREMENT or not seems to make no substantial difference: the PRIMARY KEY directive means that the values are constrained to be unique, and trying to write a NULL value will mean a new value is autogenerated anyway, either by incrementing or by finding an unused value.

Related GPKG issue where people argue about whether various GPKG tables should be AUTOINCREMENT or not: hard to come to an agreement because it makes little difference either way. There's a slight performance penalty, but you have the surety that you haven't reused any primary keys (if that's what you want).
opengeospatial/geopackage#517

The exception is that ArcPro seems to require that AUTOINCREMENT be present in the INTEGER PRIMARY KEY column. I can't test this myself, but I am assured that the lack of it caused ArcPro to fail at editing a GPKG, and adding it back in fixed it.

GPKG's generated by sno don't currently have any AUTOINCREMENT directives, regardless of whether some were present in the GPKG before import.

We can't easily detect during import if a column is AUTOINCREMENT or not, for two reasons:

  1. the sqlite PRAGMA directives don't include this information. There's a hack where you can query if there is a next-value stored in the sqlite_sequence table, if there is then the table must be AUTOINCREMENT - it only works if for tables that have contents, which admittedly is most tables. Almost all tables that a user would want to import will have content.
  2. The actual reason: we don't import from GPKG directly - we import through OGR. OGR doesn't report whether a column is AUTOINCREMENT or not. We could import through OGR and also inspect the GPKG directly but seems like a lot of effort to go to just to check if a primary key column is AUTOINCREMENT, when it hardly makes any difference - either we want always AUTOINCREMENT to better support ArcPro, or, we don't really care if we have AUTOINCREMENT or not - it hardly makes any difference.

Suggested fix: just add AUTOINCREMENT for INTEGER PRIMARY KEY columns when generating GPKG. This should fix ArcPro, and other clients probably don't care.

@olsen232 olsen232 self-assigned this Aug 4, 2020
@rcoup
Copy link
Member

rcoup commented Aug 4, 2020

Suggested fix: just add AUTOINCREMENT for INTEGER PRIMARY KEY columns when generating GPKG. This should fix ArcPro, and other clients probably don't care.

Seems reasonable for now 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants