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

feat: Add encoding option for copy_to method

Open thiagofportella opened this issue 2 years ago • 6 comments

This PR aims to add an encoding option for copy_to methods. If none is specified, it defaults to UTF8.

thiagofportella avatar Jan 27 '23 17:01 thiagofportella

thanks for the PR @thiagofportella , could you add a test case for the new feature?

diogob avatar Jan 28 '23 00:01 diogob

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!

thiagofportella avatar Jan 28 '23 22:01 thiagofportella

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?

According to the docs PG will use the current client encoding.

diogob avatar Jan 30 '23 20:01 diogob

@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.

diogob avatar Feb 06 '23 14:02 diogob

@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.

@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: Captura de Tela 2023-02-12 às 20 47 54

It seems that the encoding option in the query has no relevance in the final result.

thiagofportella avatar Feb 12 '23 23:02 thiagofportella

@thiagofportella I'll take a closer look on this

diogob avatar Feb 13 '23 14:02 diogob