Re: generate CSV with Copy+Quotes - Postgres 9.2

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Patrick B <patrickbakerbr(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: generate CSV with Copy+Quotes - Postgres 9.2
Date: 2016-09-21 15:00:11
Message-ID: CANu8FiyeG2qSm+zQxGawmQOV1T+9C9AvS=1z+b7Vj7rH8k+O4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Sep 21, 2016 at 9:33 AM, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> On 09/21/2016 02:23 AM, Patrick B wrote:
>
>> Hi guys,
>>
>> I'm exporting some data for testing purpose.
>>
>> COPY (SELECT
>> name_first
>> name_last,
>> email,
>> company
>> FROM
>> clients
>> )
>> TO '/var/lib/pgsql/test1.csv' DELIMITER ',' csv HEADER QUOTE '"';
>>
>>
>>
>> cat /var/lib/pgsql/test1.csv
>>
>> "","",hiddenemail(at)hotmail(dot)com
>> <mailto:hiddenemail(at)hotmail(dot)com>,"",John Wayne
>>
>>
> In your COPY you have fields and in the CSV file you have five.
> Are you looking at the correct file?
>
>
>> See how the email and the company aren't into two "?
>>
>
> Have no idea what you are trying to say.
>
> hiddenemail(at)hotmail(dot)com looks like a correct email to me.
>
> Maybe if you show what the data is in the table?
>
>
>> *What I need is:*
>>
>> "","","hiddenemail(at)hotmail(dot)com
>> <mailto:hiddenemail(at)hotmail(dot)com>","","John Wayne"
>>
>>
>> I thought that by putting QUOTE the COPY would do that?
>>
>> Is there any way I can put the " into those fields?
>>
>> Cheers
>>
>> Patrick
>>
>>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

Perhaps you mean you want to quote of all strings? For that you use FORCE
QUOTE.
eg:
COPY (SELECT
name_first
name_last,
email,
company
FROM
clients
)
TO '/var/lib/pgsql/test1.csv' DELIMITER ','
csv HEADER QUOTE '"';
FORCE QUOTE name_first, name_last, email, company;

Please RTFM
*https://www.postgresql.org/docs/9.4/static/sql-copy.html
<https://www.postgresql.org/docs/9.4/static/sql-copy.html>*
--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Petrie, P.Eng. 2016-09-21 18:50:06 Re: overwrite column data select - Postgres 9.2
Previous Message Adrian Klaver 2016-09-21 13:33:02 Re: generate CSV with Copy+Quotes - Postgres 9.2