feat: Add encoding option for copy_to method
This PR aims to add an encoding option for copy_to methods. If none is specified, it defaults to UTF8.
thanks for the PR @thiagofportella , could you add a test case for the new feature?
thanks for the PR @thiagofportella , could you add a test case for the new feature?
Sure, @diogob!
While writing some specs, I've had some issues encoding the return of PG::Connection#get_copy_data. It seems that, if no decoder argument is specified, the string returned is always encoded in ASCII-8BIT.
https://www.rubydoc.info/gems/pg/PG%2FConnection:get_copy_data
Got any ideas on this matter?
Thanks for the awesome work, btw!
While writing some specs, I've had some issues encoding the return of
PG::Connection#get_copy_data. It seems that, if nodecoderargument is specified, the string returned is always encoded in ASCII-8BIT. https://www.rubydoc.info/gems/pg/PG%2FConnection:get_copy_dataGot any ideas on this matter?
According to the docs PG will use the current client encoding.
@thiagofportella it seems that writing the file during the CI might be more trouble than necessary. Perhaps it is easier just to have a fixture in the repository with a known encoding and compare data from a list during the test. Just like the copy_to_enumerator tests are written.
This would also avoid calling file during the tests reducing external dependencies for the test suite.
@thiagofportella it seems that writing the file during the CI might be more trouble than necessary. Perhaps it is easier just to have a fixture in the repository with a known encoding and compare data from a list during the test. Just like the
copy_to_enumeratortests are written. This would also avoid callingfileduring the tests reducing external dependencies for the test suite.
@diogob, makes sense!
However, changing the encoding option to UTF8 in the first spec, the test didn't fail. I suspect that the changes in this PR doesn't take any effects, after all:

It seems that the encoding option in the query has no relevance in the final result.
@thiagofportella I'll take a closer look on this