agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
psql -c "\copy table to test.csv with CSV" - french character is wrong
5+ messages / 3 participants
[nested] [flat]

* psql -c "\copy table to test.csv with CSV" - french character is wrong
@ 2017-11-23 16:42 Emi <emilu@encs.concordia.ca>
  2017-11-23 18:24 ` Re: psql -c "\copy table to test.csv with CSV" - french character is wrong Pierre Chevalier Géologue <pierrechevaliergeol@free.fr>
  2017-11-24 06:28 ` Re: psql -c "\copy table to test.csv with CSV" - french character is wrong David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 2 replies; 5+ messages in thread

From: Emi @ 2017-11-23 16:42 UTC (permalink / raw)
  To: pgsql-sql

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.
-- 
. French characters show correctly in t1
. Client/server encoding: UTF8
. Cannot use super user: postgre
. Version 8.3.18





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: psql -c "\copy table to test.csv with CSV" - french character is wrong
  2017-11-23 16:42 psql -c "\copy table to test.csv with CSV" - french character is wrong Emi <emilu@encs.concordia.ca>
@ 2017-11-23 18:24 ` Pierre Chevalier Géologue <pierrechevaliergeol@free.fr>
  2017-11-23 18:57   ` Re: psql -c "\copy table to test.csv with CSV" - french character is wrong Emi <emilu@encs.concordia.ca>
  1 sibling, 1 reply; 5+ messages in thread

From: Pierre Chevalier Géologue @ 2017-11-23 18:24 UTC (permalink / raw)
  To: emilu@encs.concordia.ca; pgsql-sql

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
____________________________________________________________________________




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: psql -c "\copy table to test.csv with CSV" - french character is wrong
  2017-11-23 16:42 psql -c "\copy table to test.csv with CSV" - french character is wrong Emi <emilu@encs.concordia.ca>
  2017-11-23 18:24 ` Re: psql -c "\copy table to test.csv with CSV" - french character is wrong Pierre Chevalier Géologue <pierrechevaliergeol@free.fr>
@ 2017-11-23 18:57   ` Emi <emilu@encs.concordia.ca>
  0 siblings, 0 replies; 5+ messages in thread

From: Emi @ 2017-11-23 18:57 UTC (permalink / raw)
  To: Pierre Chevalier Géologue <pierrechevaliergeol@free.fr>; pgsql-sql


> sql2csv "SELECT DISTINCT opid, year FROM public.field_observations 
> ORDER BY year LIMIT 10" > /tmp/rien.csv
>
Ok. Will use stdout then.

Thanks.
--
psql  -c "copy t1 to STDOUT with CSV" >! test.csv




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: psql -c "\copy table to test.csv with CSV" - french character is wrong
  2017-11-23 16:42 psql -c "\copy table to test.csv with CSV" - french character is wrong Emi <emilu@encs.concordia.ca>
@ 2017-11-24 06:28 ` David G. Johnston <david.g.johnston@gmail.com>
  2017-11-24 14:47   ` Re: psql -c "\copy table to test.csv with CSV" - french character is wrong Emi <emilu@encs.concordia.ca>
  1 sibling, 1 reply; 5+ messages in thread

From: David G. Johnston @ 2017-11-24 06:28 UTC (permalink / raw)
  To: emilu@encs.concordia.ca <emilu@encs.concordia.ca>; +Cc: pgsql-sql

On Thursday, November 23, 2017, Emi <emilu@encs.concordia.ca> wrote:

>
> Tried:
>    psql -h db1 -U u1   -d d1 -c "\copy t1 to test.csv with CSV ENCODING
> 'UTF8' "
>    Got: \copy: parse error at "encoding"
>
>
You are mixing obsolete and non-obsolete syntax.  The current
syntax requires parentheses around the with options and all options written
as key-value pairs.

David J.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: psql -c "\copy table to test.csv with CSV" - french character is wrong
  2017-11-23 16:42 psql -c "\copy table to test.csv with CSV" - french character is wrong Emi <emilu@encs.concordia.ca>
  2017-11-24 06:28 ` Re: psql -c "\copy table to test.csv with CSV" - french character is wrong David G. Johnston <david.g.johnston@gmail.com>
@ 2017-11-24 14:47   ` Emi <emilu@encs.concordia.ca>
  0 siblings, 0 replies; 5+ messages in thread

From: Emi @ 2017-11-24 14:47 UTC (permalink / raw)
  To: pgsql-sql@lists.postgresql.org

Hello,
>
>
>     Tried:
>        psql -c "\copy t1 to test.csv with CSV ENCODING 'UTF8' "
>        Got: \copy: parse error at "encoding"
>
>
> mixing obsolete and non-obsolete syntax. requires parentheses around 
> with options and all options written as key-value pairs.
I think you mean 9.x. My version is 8.x, and doc shows ENCODING 
'encoding_name' only for 9.x. I will use stdout for 8.x.

Thanks.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2017-11-24 14:47 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-11-23 16:42 psql -c "\copy table to test.csv with CSV" - french character is wrong Emi <emilu@encs.concordia.ca>
2017-11-23 18:24 ` Pierre Chevalier Géologue <pierrechevaliergeol@free.fr>
2017-11-23 18:57   ` Emi <emilu@encs.concordia.ca>
2017-11-24 06:28 ` David G. Johnston <david.g.johnston@gmail.com>
2017-11-24 14:47   ` Emi <emilu@encs.concordia.ca>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox