Re: Formating psql query output

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Formating psql query output
Date: 2021-07-19 19:21:37
Message-ID: CAFj8pRD29wtSY2AG6K3V=3BovqU6=XkJoviXgsnm_fe8_x6UPg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

po 19. 7. 2021 v 21:12 odesílatel Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
napsal:

>
>
> po 19. 7. 2021 v 21:07 odesílatel Rich Shepard <rshepard(at)appl-ecosys(dot)com>
> napsal:
>
>> On Mon, 19 Jul 2021, Rob Sargent wrote:
>>
>> > Can we see on line of the csv output? The field with commas should be in
>> > quotes, no? You’ll have write a “real” csv importer. awk =F”\”*,*\””
>> > might, heavy on the might.
>>
>> Rob,
>>
>> Here's a redacted output line:
>>
>> 8,2019-04-08,Phone,Went to voice mail @ 14:48; didn't leave a message.
>> Call
>> Wednesday morning,8,<lname>,<fname>,537,537,<company_name>
>>
>> No quoted text fields.
>>
>
> text fields are quoted only when it is necessary
>
> [pavel(at)localhost src]$ psql -c "select 'ahoj' as x, 'svete' as y" --csv
> Assertions: on
> x,y
> ahoj,svete
> [pavel(at)localhost src]$ psql -c "select 'ahoj' as x, 'sve,te' as y" --csv
> Assertions: on
> x,y
> ahoj,"sve,te"
>
> If you need forced quoting, you need to use COPY TO STDOUT statement
>

[pavel(at)localhost src]$ psql -c "copy (select 'ahoj' as x, 'svete' as y) to
stdout force quote * csv header"
Assertions: on
x,y
"ahoj","svete"

>
> Regards
>
> Pavel
>
>>
>> Rich
>>
>>
>>
>>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2021-07-19 20:04:09 Re: Formating psql query output
Previous Message Pavel Stehule 2021-07-19 19:12:02 Re: Formating psql query output