3

Using ogr2ogr to import a GeoPackage to a PostGIS database, I want to cast a field to another type, using -lco COLUMN_TYPES=

The field name, however has a dash in it's name. I tried:

-lco COLUMN_TYPES="\"plus-type\"=text"

-lco COLUMN_TYPES="\\"plus-type\\"=text"

-lco COLUMN_TYPES="plus-type=text"

So how do I specify the a fieldname which in PostreSQL should be double quoted?

1 Answer 1

4

I had a try and I did not need to do anything special, despite to disable the name laundering that by default changes the dash character into underscore. See https://gdal.org/drivers/vector/pg.html

LAUNDER=[YES/NO]: Defaults to YES. This may be "YES" to force new fields created on this layer to have their field names "laundered" into a form more compatible with PostgreSQL. This converts to lower case and converts some special characters like "-" and "#" to "_". If "NO" exact names are preserved. If enabled the table (layer) name will also be laundered.

I run ogr2ogr with these parameters

-lco column_types=plus-type=text -lco launder=no

The column "plus-type" was integer in the source data and ogrinfo shows now about the new PostGIS table that the column type is changed into text.

FID Column = ogc_fid
Geometry Column = wkb_geometry
plus-type: String (0.0)
OGRFeature(lcotest):1
  plus-type (String) = 3
  POINT (309 269)
2
  • thanks. I should have mentioned that I allready had -lco launder=no in my parameters. That said, your solution works! So it must have been the double quotes. Commented Jul 24, 2023 at 15:53
  • This works also for me -lco column_types="plus-type"=text -lco launder=no.
    – user30184
    Commented Jul 24, 2023 at 16:08

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.