Re: Formating psql query output - Mailing list pgsql-general

From Pavel Stehule
Subject Re: Formating psql query output
Date
Msg-id CAFj8pRB6WTJZoiO0RFWXxSdY-YHaQu7Rf073hJyTF-J4NuB+WQ@mail.gmail.com
Whole thread Raw
In response to Re: Formating psql query output  (Rich Shepard <rshepard@appl-ecosys.com>)
Responses Re: Formating psql query output  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-general


po 19. 7. 2021 v 21:07 odesílatel Rich Shepard <rshepard@appl-ecosys.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@localhost src]$ psql -c "select 'ahoj' as x, 'svete' as y" --csv
Assertions: on
x,y
ahoj,svete
[pavel@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

Regards

Pavel

Rich



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Formating psql query output
Next
From: Pavel Stehule
Date:
Subject: Re: Formating psql query output