title: PSQL COPY statement error says character is encoded WIN1252 despite file seeming to be encoded UTF-8
body: <p>I am trying to copy a CSV I created in Python to a PSQL database using a copy statement and am receiving the error <code>PostgreSQL: character with byte sequence 0xc2 0x81 in encoding “UTF8” has no equivalent in encoding “WIN1252”</code>.</p>
  <p>The original file was UTF-8, and I'm fairly certain the file I created and am trying to copy is encoded with UTF-8. I believe I added the correct params in my Python code:</p>
  <pre><code>def process_csvs():
      with open('movie_file.csv', mode='w', encoding='utf-8') as movie_file:
          movie_writer = csv.writer(movie_file, delimiter=',', quotechar='&quot;', quoting=csv.QUOTE_MINIMAL, lineterminator='\n')
          with open('movie_basics.tsv', encoding='utf-8') as csv_file:
              csv_reader = csv.reader(csv_file, delimiter=&quot;\t&quot;)
              for row in csv_reader:
                  ...
  </code></pre>
  <p>When I open the output file in notepad, it says the encoding is UTF-8.</p>
  <p>My COPY statement is as follows:</p>
  <pre><code>COPY movies(movie_id, title, year, runningtime) FROM 'C:\Users\Public\Documents\movie_file.csv' DELIMITER ',' CSV HEADER NULL AS 'Nul
  l';
  </code></pre>
  <p>I believe the character that is currently giving me trouble is is the accented A in: <code>tt0000676,Don Álvaro o la fuerza del sino,1908,Null</code></p>
  <p>Anybody know how it could be encoded WIN1252 with my configuration and any way to fix it? Thanks!</p>
  <p>EDIT:</p>
  <p>I recreated the database with:</p>
  <pre><code>CREATE DATABASE &quot;scratch&quot;
    WITH TEMPLATE template0
    ENCODING 'UTF8'
    LC_COLLATE = 'en_US.UTF-8'
    LC_CTYPE = 'en_US.UTF-8';
  </code></pre>
  <p>As far as I can see, everything involved is encoded in UTF-8 outside of perhaps the command line, which I believe defaults to WIN1252. I am pretty new to all of this. And I did attempt to write the file with WIN1252 encoding in my Python script, but the original data is encoded UTF-8, and the script threw errors attempting to make the conversion.</p>