OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.84k stars 2.53k forks source link

Mechanism in OGR core to prevent creating duplicate field names? #11060

Open rouault opened 13 hours ago

rouault commented 13 hours ago

Stepping back a bit from https://github.com/OSGeo/gdal/pull/11059, I'm wondering if OGRLayer::CreateField() shouldn't rather be renamed ICreateField() and have a non-virtual method OGRLayer::CreateField() that calls driver-overridden ICreateField(). Before doing that it could do some sanity checks like checking that there is no duplicate field names. Although there are drivers that probably somehow support it (CSV ? I also believe that Parquet itself supports duplicate field names, although the OGR driver probably does not). So perhaps there should be some OLCSupportsDuplicateFieldNames capability to condition that test?

Perhaps expose the maximum number of columns too? Limitations on field names ?

theroggy commented 4 hours ago

Are there file formats that use case sensitive column names? If that would be the case this is also something to think about.

Probably the same logic is applicable to renaming column names. In this regard, I noticed that if you rename a column while only changing the casing via an ALTER TABLE it isn't renamed. To do this you first need to rename to a really different name and then to the name with different casing.

jratike80 commented 3 hours ago

Are there file formats that use case sensitive column names?

PostGIS certainly, I think Oracle too and other "real" databases except SQLite.

theroggy commented 11 minutes ago

Are there file formats that use case sensitive column names?

PostGIS certainly, I think Oracle too and other "real" databases except SQLite.

In Oracle this is not the case, unless you put double quotes around a column name... Based on a quick google it is similar in PostGIS: case insensitive unless double quoted, but still slightly different to PostGIS. Now I remember that MS SQL Server does have case sensitive naming (or at least had 15 years ago).

But indeed, I didn't think about the "double quoting" case...