title: PostgreSQL Copy To - CSV filename encoding
body: <p>I have a database setup with a UTF-8 encoding. Trying to copy a table to csv, where the filename has a special character writes out the filename wrong to disk.</p>
  
  <p>On a Windows 10 localhost PostgreSQL installation:</p>
  
  <pre><code>copy
    (select 'tønder')
  to 'C:\temp\Sønderborg.csv' (FORMAT CSV, HEADER TRUE, DELIMITER ';', ENCODING 'UTF8');
  </code></pre>
  
  <p>Names the csv file: SÃ¸nderborg.csv and not Sønderborg.csv.</p>
  
  <p>Both</p>
  
  <pre><code>SHOW CLIENT ENCODING;
  SHOW SERVER_ENCODING;
  </code></pre>
  
  <p>returns UTF8</p>
  
  <p>How can one control the csv filename encoding? The encoding inside the csv is ok writing Tønder!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have run the <em>copy</em> command from pgAdmin, DataGrip and a psql console. DataGrip uses JDBC and will only handle UTF8. All three applications writes the csv filename in wrong encoding. The only difference is that the psql console says the client encoding is WIN1252.</p>