postgres-copy icon indicating copy to clipboard operation
postgres-copy copied to clipboard

Feature proposal: Map column names when exporting CSV

Open DanielHeath opened this issue 8 years ago • 3 comments

I'm seeing an issue where column names are:

A) converted to lowercase (they are uppercase in the SQL) B) cannot be remapped in ruby code (without hacking around in the enumerator).

Would a PR to add the map: {} syntax to CSV exports be mergeable?

DanielHeath avatar Jun 15 '17 00:06 DanielHeath

Sorry, I don't follow you. Could you paste a snippet of the desired code that you would like to use?

diogob avatar Jun 15 '17 02:06 diogob

Lets say you have CSV imports and exports, and want round-tripping to work.

You export with:

Foo.select('bar as Baz').copy_to_string

then import with:

Foo.copy_from filename, :map => {'Baz' => 'bar'}

However, the CSV from copy_to_string has a header row of baz, not Baz.

DanielHeath avatar Jun 15 '17 03:06 DanielHeath

I see your point. It makes sense to have symetrical APIs on exports and imports.

diogob avatar Jun 21 '17 01:06 diogob