Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hY6kT-0006kA-1v for pgsql-general@arkaria.postgresql.org; Tue, 04 Jun 2019 10:32:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hY6kR-0005Y8-Fw for pgsql-general@arkaria.postgresql.org; Tue, 04 Jun 2019 10:32:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hY6kR-0005Y1-66 for pgsql-general@lists.postgresql.org; Tue, 04 Jun 2019 10:32:55 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hY6kK-00060a-46 for pgsql-general@postgresql.org; Tue, 04 Jun 2019 10:32:54 +0000 Received: from [192.168.127.1] (port=54828 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1hY6kI-00041d-1w; Tue, 04 Jun 2019 10:32:46 +0000 Received: from [127.0.0.1] (port=38062 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1hY6kH-0001r0-DH; Tue, 04 Jun 2019 10:32:45 +0000 From: Andrew Gierth To: Matthias Apitz Cc: Postgres general Subject: Re: Two small questions re/ COPY CSV data into table In-Reply-To: <20190604100247.GA2800@c720-r342378> (Matthias Apitz's message of "Tue, 4 Jun 2019 12:02:47 +0200") Message-ID: <877ea1aby6.fsf@news-spur.riddles.org.uk> References: <20190604100247.GA2800@c720-r342378> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Tue, 04 Jun 2019 11:32:45 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Matthias" == Matthias Apitz writes: Matthias> ... WITH DELIMITER '|', FORMAT CSV ; I think you misread the docs; the new-style syntax would be COPY ... WITH (DELIMITER '|', FORMAT CSV); where the parens are not optional. The old-style syntax with no parens after WITH is what you were using before. Matthias> 2. The CSV export is done by some Sybase tool which escapes Matthias> the delimiter as '\|', i.e. putting a backslash before the Matthias> delimiter. I found no way that COPY understands this Matthias> excaping. Any ideas? That sounds like the file is not actually a CSV - why do you think it is? PG accepts two formats (actually 3 if you count binary format which is rarely used): TEXT: records are delimited by newlines, columns are delimited by a delimiter character (default tab), there are no quotation marks, any newline, backslash, or delimiter in the data must be escaped as a backslash-sequence (e.g. \n or \012) CSV: columns may be quoted (in which case delimiters and newlines inside them are ignored), records are delimited by newlines _outside_ quoted fields, there are no backslash-sequences or escapes outside of quoted fields, quote characters inside quoted fields are doubled (though there's an option to change this). PG follows the CSV spec at https://www.ietf.org/rfc/rfc4180.txt fairly closely. -- Andrew (irc:RhodiumToad)