Bug report #12112

"Save as" fails to export from PostGIS (or Spatialite) to CSV when the are two columns with the same name (one uppercase)

Added by Stefan Blumentrath almost 10 years ago. Updated about 9 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Data Provider/OGR
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:20306

Description

QGIS does not export a layer containing a column named ID to CSV using "Save as" dialog.

See discussion here:
http://lists.osgeo.org/pipermail/qgis-developer/2015-January/036554.html

Just tested ogr2ogr -f CSV and used the same PostGIS layer I tried to "Save as" CSV from within QGIS.
OGR gives a warning that it renamed the existing ID column to ID2 automatically and exports the layer nicely to CSV.
So the issue seems to be QGIS related...

37.png (206 KB) Raymond Nijssen, 2015-11-05 10:32 AM

History

#1 Updated by Giovanni Manghi almost 10 years ago

  • Status changed from Open to Feedback

I cannot confirm on qgis master, where it seems to work as expected. Please give qgis master a try and/or attach a sample of the data that is causing the issue to you. Cheers!

#2 Updated by Stefan Blumentrath almost 10 years ago

Just downloaded latest master (2.7.0-88 in OSGeo4W) and tried again, but i get the same error:

"Export to vector file failed.
Error: creation of field ID failed (OGR error: Attempt to create field ID, but a field with this name already exists.)"

Export to CSV however works for the same data when send through shape format first, meaning PostGIS -> Shape -> CSV works.
PostGIS -> SQLite again does not work (fails with error message above). That makes providing sample data a bit complicated...

#3 Updated by Giovanni Manghi almost 10 years ago

Stefan Blumentrath wrote:

Just downloaded latest master (2.7.0-88 in OSGeo4W) and tried again, but i get the same error:

"Export to vector file failed.
Error: creation of field ID failed (OGR error: Attempt to create field ID, but a field with this name already exists.)"

Export to CSV however works for the same data when send through shape format first, meaning PostGIS -> Shape -> CSV works.
PostGIS -> SQLite again does not work (fails with error message above). That makes providing sample data a bit complicated...

just tested again on linux and windows and no problem whatsoever.

#4 Updated by Stefan Blumentrath almost 10 years ago

Hi Giovanni,

thanks for looking at this.
I am having this issue on two fresh and clean OSGeo4W installations on two different Win7 computers.
Maybe I was a bit too unspecific when describing the issue and buried important information in the linked thread on the mailinglist.
The issue occurs with PostGIS layers (shape works as mentioned above). The PostGIS table contains the following columns:
"ID", id, geom
ogr2ogr (also on the machines having the issue) renames ID to id2 and exports nicely to CSV, QGIS throws the error message above and does not export.
Maybe related to (lack of) SQL quoting or UPPER/lower conversion?

Cheers
Stefan

#5 Updated by Giovanni Manghi almost 10 years ago

  • Subject changed from "Save as" fails to export CSV when a colum named ID is present in attribute table to "Save as" fails to export from PostGIS (or Spatialite) to CSV when the are two columns with the same name (one uppercase)
  • Affected QGIS version changed from 2.6.0 to master

The issue occurs with PostGIS layers (shape works as mentioned above). The PostGIS table contains the following columns:
"ID", id

well... yes, this was a fundamental bit of information to allow others try replicate...

#6 Updated by Stefan Blumentrath almost 10 years ago

Sorry, Giovanni, for the unnecessary extra work...

#7 Updated by Raymond Nijssen about 9 years ago

Hi Stefan,

We reproduced your issue. By the way, it was pretty hard to even create a PostGIS table with fields 'id' and 'ID' and I think it is a bad idea anyway.

QGIS indeed generates this error but there is another way to get this done, using Prosessing. There you will find the ogr tool 'Convert format' which uses ogr2ogr in the background and therefore generates a valid CSV file. I added a screenshot and will close this odd case issue now.

Thanks for reporting

#8 Updated by Raymond Nijssen about 9 years ago

  • Status changed from Feedback to Closed

Also available in: Atom PDF