Re: COPY table to file missing quotation marks

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: COPY table to file missing quotation marks
Date: 2013-01-31 16:46:25
Message-ID: 510A9FE1.8000000@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 01/31/2013 08:37 AM, Rich Shepard wrote:
> I'd like to understand what I'm missing when I COPY a table to a .csv
> file
> but the text is not quoted.
>
> Here's an example of a command:
>
> copy chemistry to '/home/postgres/emapchem.csv' with (format CSV, header
> True, quote '"', delimiter '|');
>
> and here're part of the header and following row of the output:
>
> siteid|sampdate|analdate|ph|cond|turb|tss|doc|dic|p|se|ca|mg|na|k|nh4|so4|no3
>
> 1993SBOIA049|2004-06-28|2004-06-28|7.67|117|4.21|6.1|1.13|11.96|40|0.2|503.5|206.2
>
>
> I'm sure it's something simple in the syntax I keep getting wrong, but I
> don't see it.

http://www.postgresql.org/docs/9.2/interactive/sql-copy.html

CSV Format

...
"The values in each record are separated by the DELIMITER character. If
the value contains the delimiter character, the QUOTE character, the
NULL string, a carriage return, or line feed character, then the whole
value is prefixed and suffixed by the QUOTE character, and any
occurrence within the value of a QUOTE character or the ESCAPE character
is preceded by the escape character. You can also use FORCE_QUOTE to
force quotes when outputting non-NULL values in specific columns." ...

FORCE_QUOTE
Forces quoting to be used for all non-NULL values in each specified
column. NULL output is never quoted. If * is specified, non-NULL values
will be quoted in all columns. This option is allowed only in COPY TO,
and only when using CSV format.

>
> Rich
>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2013-01-31 16:53:16 Re: COPY table to file missing quotation marks
Previous Message Rich Shepard 2013-01-31 16:37:35 COPY table to file missing quotation marks