gdal icon indicating copy to clipboard operation
gdal copied to clipboard

Postgres: Impossible to specify COLUMN_TYPES for fields which contain certain characters

Open atlight opened this issue 1 year ago • 3 comments

The pg driver supports an open option COLUMN_TYPES, which contains key-value pairs separated by commas allowing you to override Postgres field types.

However, due to the simplistic way this parameter is parsed, it seems to be impossible to override column types in certain situations:

  • where you have more than one column whose names contain open parentheses ( but no closing parenthesis ), such as Easting (m and Area (sqkm (very plausible field names from a SHP or DBF)
  • where the field name contains an equal sign = or colon :

This may seem like an edge case, but we have run into this in our production systems. I've put a crude workaround in place but it really needs to be fixed in GDAL, and it's not clear what the best way to solve it is.

atlight avatar Feb 01 '24 01:02 atlight

Maybe some backslash escaping logic? (assuming backslash are extremely unlikely to appear in column names)

rouault avatar Feb 01 '24 02:02 rouault

Good idea. Something like:

\\ → \
\= → =
\: → :

Also we could restrict the special parsing of ( ) to after an = or : delimiter has been encountered, as it is not needed in the column name (key) portion of the input.

atlight avatar Feb 01 '24 02:02 atlight

@atlight I let it to you?

rouault avatar Feb 01 '24 12:02 rouault