CartoDB-SQL-API icon indicating copy to clipboard operation
CartoDB-SQL-API copied to clipboard

export to csv with default column names fails

Open javisantana opened this issue 10 years ago • 8 comments

http://javi.cartodb.com/api/v1/sql?q=select%20st_astext(st_makepoint(0,0))&format=csv

javisantana avatar Nov 03 '14 16:11 javisantana

@javisantana by "fails" I understand that you're getting an empty document, right? I'm not getting any errors, just a blank CSV.

fdansv avatar Jun 05 '15 09:06 fdansv

I think this is the same problem than #204

javisantana avatar Jun 05 '15 10:06 javisantana

It's not the same problem, check:

https://documentation.cartodb.com/api/v1/sql?q=select%20st_astext(st_makepoint(0,0))&format=csv

vs

https://documentation.cartodb.com/api/v1/sql?q=select%20st_astext(st_makepoint(0,0))%20p&format=csv

rochoa avatar Jun 05 '15 13:06 rochoa

ok!

javisantana avatar Jun 05 '15 13:06 javisantana

vamos!

fdansv avatar Jun 05 '15 14:06 fdansv

https://github.com/OSGeo/gdal/blob/trunk/gdal/ogr/ogrsf_frmts/pg/ogrpglayer.cpp#L1387-L1403

pramsey avatar Jun 09 '15 17:06 pramsey

Here's where it actually gets called

https://github.com/OSGeo/gdal/blob/trunk/gdal/ogr/ogrsf_frmts/pg/ogrpglayer.cpp#L2075

OGR is trying to catch queries that generate geometry (in both binary and text representations) and avoid putting those representations into non-geometry columns. It does so in your test because you use a common output function signature (st_astext) and then output to a format that OGR doesn't write geometry into by default (so the column "disappears")

pramsey avatar Jun 09 '15 17:06 pramsey

Options:

  • rewrite the query slightly before handing it to OGR to avoid using the "magic function names" as column names
  • add a config parameter to OGR to make the "magic name passing" behavior optional

pramsey avatar Jun 09 '15 17:06 pramsey