pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Smith <greg@2ndquadrant.com>
To: Lou Picciano <loupicciano@comcast.net>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: How To: LARGE html text or csv file COPY FROM?
Date: Wed, 15 Sep 2010 21:26:36 -0400
Message-ID: <4C91724C.4040802@2ndquadrant.com> (raw)
In-Reply-To: <594168409.400001.1284555796001.JavaMail.root@sz0093a.westchester.pa.mail.comcast.net>
References: <594168409.400001.1284555796001.JavaMail.root@sz0093a.westchester.pa.mail.comcast.net>

Lou Picciano wrote:p { margin: 0; }
> Both errors above make sense to me; COPY is running into either a cr 
> or a tab character in each case.

Even though they might seem very similar at first, text mode and CSV 
mode work very differently here.  To quote TFM at 
http://www.postgresql.org/docs/current/static/sql-copy.html , which 
covers all this if you dig into it enough:

"CSV mode will both recognize and produce CSV files with quoted values 
containing embedded carriage returns and line feeds. Thus the files are 
not strictly one line per table row like text-mode files."

So as long as the field is quoted, you can have a CR or tab in the middle.

In text mode:  "the following characters /must/ be preceded by a 
backslash if they appear as part of a column value: backslash itself, 
newline, carriage return, and the current delimiter character."  Text 
mode will therefore require escaping everything on that list.

So if this is close to being importable in CSV mode, you might just need 
to wrap the HTML field with a pair of quotes, and escape any quote 
characters that are inside of it.  Text mode is going to require a whole 
escaping run of all the reserved characters that are input.

-- 
Greg Smith, 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD
PostgreSQL Training, Services and Support  www.2ndQuadrant.us
Author, "PostgreSQL 9.0 High Performance"    Pre-ordering at:
https://www.packtpub.com/postgresql-9-0-high-performance/book

view thread (2+ messages)

Message-ID: <4C91724C.4040802@2ndquadrant.com>
Permalink:  ../4C91724C.4040802@2ndquadrant.com/
Also on:    postgresql.org/message-id/4C91724C.4040802@2ndquadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: greg@2ndquadrant.com, loupicciano@comcast.net
  Subject: Re: How To: LARGE html text or csv file COPY FROM?
  In-Reply-To: <4C91724C.4040802@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox