1

Using GDAL's ogr2ogr to load data from a DBF I've downloaded from a proprietary system into PostgreSQL. The data has date fields where no-data records are stored as 0000/00/00, so I'm using SQLite's NULLIF function to change these to proper NULL values; if I left them, ogr2ogr was producing errors being unable to handle the date values. As a result of using SQLite though, I'm then facing the issue of SQLite not handling the Boolean fields properly. I know SQLite doesn't have a Boolean type, but I'm expecting it to just be treated as a standard integer in that case, however I'm unable to get it to keep the True values as 1, with everything instead just going to 0 (i.e. False). I've tried experimenting forcing the casting via -sql "SELECT CAST(field AS Integer) FROM table" and also -mapFieldType Integer(Boolean)=Integer.

I've tried doing ogrinfo and also doing ogr2ogr into a different format, however it appears the issue is consistent once using a SQLite query. I have made a sample version of the dataset available at https://github.com/trodaway/filesharing/blob/main/example.dbf

Is there a way round this?

Note: I have been using GDAL 3.9.1, although the date issue should be resolved in the recently released 3.9.2, so I might be able to get around the boolean issue with this, however this doesn't fix the root cause issue if it does happen to be a bug.

4
  • Can't you depersonalise the .dbf? Just keep a few rows in it and only keep the columns relevant for this problem will probably lead to the .dbf being ok to share?
    – Pieter
    Commented Aug 28 at 13:05
  • Also: what version of GDAL are you using, as I remember a problem with booleans being fixed a while ago? If you are not using the latest version, try with the latest version please...
    – Pieter
    Commented Aug 28 at 13:07
  • I've just added an example dbf. As I've edited my question to note, I've been using 3.9.1, however just updated to 3.9.2 so will try again - from the looks of the release notes, it should fix the date issue meaning I don't need to use SQLite, although that's just a workaround opposed to addressing the actual issue with the booleans.
    – Tim R
    Commented Aug 28 at 18:02
  • 1
    Ah, I've tried again using the latest version (I thought I was, as only installed it in the last few weeks) and that works - thanks for the reminder to check that :)
    – Tim R
    Commented Aug 28 at 19:23

1 Answer 1

1

A problem with booleans was fixed a while ago in GDAL...

Please try with the latest GDAL version (3.9.2) please.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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