Wrong string encoding for COPY TO STDOUT FORMAT CSV

Issue #259 new
flop
created an issue

While trying to output some CSV using COPY TO STDOUT FORMAT CSV, I get a string with the wrong encoding. At first I thought it was coming from Sequel but Jeremy Evans found out the problem was in pg ( https://github.com/jeremyevans/sequel/issues/1325 ) :

Here is the script to help reproduce :

#!/usr/bin/env ruby

require 'pg'

conn = PG.connect( :dbname => 'template1' )
$stderr.puts '---',
    RUBY_DESCRIPTION,
    PG.version_string( true ),
    "Server version: #{conn.server_version}",
    "Client version: #{PG.respond_to?( :library_version ) ? PG.library_version : 'unknown'}",
    '---'

conn.exec("COPY (SELECT '\u2714' AS checked) TO STDOUT (FORMAT csv, ENCODING UTF8)")

while s = conn.get_copy_data
  p s.encoding
end

$stderr.puts %Q{Expected this to return: #<Encoding:UTF-8>}

and the output :

---
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
PG 0.20.0 (build 838985377b48)
Server version: 90502
Client version: 90502
---
#<Encoding:ASCII-8BIT>
Expected this to return: #<Encoding:UTF-8>

Comments (0)

  1. Log in to comment