Saturday 28 July 2018

QGIS Offline editing of PostGIS table produces a Spatialite table with no attribute lengths?


When synchronizing an offline Spatialite file with it's corresponding PostGIS database, using the Offline Editing plugin in QGIS, I received an error I hadn't experienced before


enter image description here


The error message is quite clear, I had entered more than 254 characters in a attribute field that in the PostGIS table had this field length.


I looked at the properties of the offline Spatialite table and all the attribute length and precisions are all '0', or undefined. enter image description here


In the original PostGIS database table they are defined



enter image description here


Even if the Spatialite attribute that is too long is corrected, the synchronising of the offline Spatialite file now gives a commit error, which means all the changes made offline will now not synchronise.


enter image description here


My question


Is it possible to bring across the attribute field lengths from the PostGIS table to the Spatialite file so as to not allow attributes that are too long to be entered in the first instance?



Answer



With all credit to user30184 who answered in the comments...


SQLite just doesn't care. From sqlite.org/datatype3.html



Note that numeric arguments in parentheses that following the type name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large global SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric values.




So the answer to the question is No, it is not possible to bring across the attribute field lengths from the PostGIS table to the Spatialite file.


This means that there is no limit to the length of what you can enter in the attribute fields. This is fine if you are working in SQLite and you want to stay working in SQLite, however if you then want to synchronise an SQLite database that was 'offlined' from a PostGIS database you will run into problems if the field lengths are greater than those set up in the PostGIS database.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...