jkall / qgis-midvatten-plugin

Midvatten plugin for QGIS
23 stars 8 forks source link

Import errors for Postgis tables where unit can be NULL #338

Closed HenrikSpa closed 2 years ago

HenrikSpa commented 2 years ago

The column unit in w_qual_field is a primary key, but can be NULL in the SQLite-database. However, in the Postgis database this is not allowed and the column is "not null" automatically.

When we import data using General csv import, empty string is automatically converted into NULL-values:

args = tuple([None if any([r is None, (isinstance(r, str) and not r.strip()) if r is not None else None]) else r for r in row])

The effect is that rows where unit column is NULL or empty string is excluded during import!


If we remove the conversion from empty string to NULL the database will be filled with lots of empty strings instead of NULL values even for columns where we would prefer NULL values.

A solution might be to add a special case for w_qual_field (and maybe other tables that are affected).

HenrikSpa commented 2 years ago

Fixed by converting NULL-values to empty string for unit column when importing to w_qual_field-table. Trims spaces at beginning and end of unit and turns rows with only space into empty string.