Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHwB5-0001QF-Il for pgsql-sql@arkaria.postgresql.org; Thu, 23 Nov 2017 18:24:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHwB4-00088B-I9 for pgsql-sql@arkaria.postgresql.org; Thu, 23 Nov 2017 18:24:46 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eHwB4-00087z-8n for pgsql-sql@lists.postgresql.org; Thu, 23 Nov 2017 18:24:46 +0000 Received: from p3plsmtpa07-04.prod.phx3.secureserver.net ([173.201.192.233]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eHwB1-0001ja-Au for pgsql-sql@postgresql.org; Thu, 23 Nov 2017 18:24:45 +0000 Received: from [192.168.1.47] ([92.136.214.115]) by :SMTPAUTH: with SMTP id HwAxeJJO1uB6oHwAyemaCF; Thu, 23 Nov 2017 11:24:41 -0700 X-Sender: pchevalier@afrexgeoservices.com Subject: Re: psql -c "\copy table to test.csv with CSV" - french character is wrong To: emilu@encs.concordia.ca, pgsql-sql@postgresql.org References: <7c6b8218-bdde-1c0a-2cbf-f817b37c2a2f@encs.concordia.ca> From: =?UTF-8?Q?Pierre_Chevalier_G=c3=a9ologue?= Message-ID: <0fab017c-ada9-e64f-a889-57e868c35230@free.fr> Disposition-Notification-To: =?UTF-8?Q?Pierre_Chevalier_G=c3=a9ologue?= Date: Thu, 23 Nov 2017 19:24:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <7c6b8218-bdde-1c0a-2cbf-f817b37c2a2f@encs.concordia.ca> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfCGqTLj8UBQW/83K4+wrbgH2TrrGyMZQzYrJZtlJZVoGADjwH+EwsAEVvcUvv3hV+ryF33PVdGUEdYnjNwFXI2Qmou5GpLEjJv6x1fDruTBL4pPn+iAU z9ZGpUZPJ3EUHVnhZDzvSnQ/Yg5f+YYONFOQ/mbymNJiBVFEcNt8XhARyKz/L3RGqY3xKFyg/rXNNg9M7Giv40r88npVGIRUx/SQbr6r9loKaq5o2h+NQViw List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk HelloBonsoir, Which operating system are you dealing with on the client side? For this kind of purpose, I have a handy script which does the job flawlessly, I've never had problems with any wéird frènch âccènts. I don't use the \c command, but the COPY TO syntax, rather. I can't remember the reason why, but it just works. Here's the complete script: # pierre@latitude: ~ < 2017_11_23__19_07_35 > cat bin/sql2csv #!/bin/sh # (c) Pierre Chevalier # Ce script fait un fichier csv à partir de la bd postgresql GLL_BD_NAME dans l'hôte GLL_BD_HOST, avec la requête en entrée # This script creates a csv file from the postgresql database GLL_BD_NAME served by GLL_BD_HOST host, with the query specified as a double-quoted string input #$1: requete #$2: fichier de sortie .csv => bof, non, on redirige, plutôt #$1: query #$2: .csv output file => bof, no, better to just redirect or pipe, later echo "COPY ($1) TO stdout WITH CSV HEADER FORCE QUOTE *" | psql -X -h $GLL_BD_HOST $GLL_BD_NAME As you can see, only the last line is relevant. I use the script as follows, after adjusting the variables are set properly: # pierre@latitude: ~ < 2017_11_23__19_07_35 > sql2csv "SELECT DISTINCT opid, year FROM public.field_observations ORDER BY year LIMIT 10" > /tmp/rien.csv # pierre@latitude: ~ < 2017_11_23__19_07_35 > cat /tmp/rien.csv opid,year "0","1946" "0","1997" "9","1997" "0","1998" "9","1998" "9","1999" "0","1999" "9","2000" "17","2000" ,"2006" # pierre@latitude: ~ < 2017_11_23__19_07_35 > I'm doing this on Debian GNU/Linux, both on client and server. In your case, you could try something like this (on one line): echo "COPY (SELECT * FROM t1) TO stdout WITH CSV HEADER FORCE QUOTE *" | psql -h db1 -U u1 -d d1 > test.csv À+ Pierre Le 23/11/2017 à 17:42, Emi a écrit : > Hello, > > Tried to run: >    psql -h db1 -U u1   -d d1 -c "\copy t1 to test.csv with CSV" > > Problem: >    French characters are not shown correctly. > > > Tried: >    psql -h db1 -U u1   -d d1 -c "\copy t1 to test.csv with CSV ENCODING > 'UTF8' " >    Got: \copy: parse error at "encoding" > > Can you help how to copy french characters correctly into csv file please? > > Thanks a lot. -- ____________________________________________________________________________ Pierre Chevalier PChGEI: Pierre Chevalier Géologue Et Informaticien Mesté Duran 32100 Condom Tél : 06 37 80 33 64 Émail : pierrechevaliergeolCHEZfree.fr Tweeter: PierreChTux icq# : 10432285 jabber: pierre.chevalier1967@jabber.fr http://pierremariechevalier.free.fr/pierre_chevalier_geologue ____________________________________________________________________________