Re: No quotes in output of "psql \copy CSV"

Поиск
Список
Период
Сортировка
Искать
От
Sam Mason
Тема
Re: No quotes in output of "psql \copy CSV"
Дата
Msg-id
20100629124039.GC7584@samason.me.uk
Ответ на
Список
Дерево обсуждения
No quotes in output of "psql \copy CSV" Arnaud Lesauvage <arnaud.listes@codata.eu>
Re: No quotes in output of "psql \copy CSV" Sam Mason <sam@samason.me.uk>
Re: No quotes in output of "psql \copy CSV" Arnaud Lesauvage <arnaud.listes@codata.eu>
On Tue, Jun 29, 2010 at 02:24:00PM +0200, Arnaud Lesauvage wrote:
> I'd like to generate CSV files from the output of a query.
> I can't get the srings in the output to be quoted though. I thought that  
> this was the default for CSV, and even adding the "QUOTE" parameter does  
> not help :
>
> postgres=# \copy (SELECT 1, 'test', 'foo', 'bar', TRUE, FALSE) TO stdout  
> CSV QUOTE '"' DELIMITER ','
> 1,test,foo,bar,t,f
>
> What am I missing here ?

By default values are only quoted when they need to be, i.e. if they
contain a quote, comma and a few other characters.  This is very common
behavior and all the programs I've tried to use the resulting files with
have been fine with it.

If you really want all values to be quoted you can include the "FORCE
QUOTE" option, i.e:

  copy (SELECT 1 AS a, 'a' AS b) TO stdout WITH CSV HEADER FORCE QUOTE a,b;

-- 
  Sam  http://samason.me.uk/
В списке pgsql-general по дате отправления
От: Arnaud Lesauvage
Дата:
От: Scott Marlowe
Дата:
FAQ