Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TOuLI-0008CM-5y for pgsql-bugs@postgresql.org; Thu, 18 Oct 2012 17:57:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TOuLC-0005CZ-1W for pgsql-bugs@postgresql.org; Thu, 18 Oct 2012 17:57:11 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q9IHv41D001602; Thu, 18 Oct 2012 13:57:04 -0400 (EDT) From: Tom Lane To: sams.james+postgres@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #7611: \copy (and COPY?) incorrectly parses nul character for windows-1252 In-reply-to: References: Comments: In-reply-to sams.james+postgres@gmail.com message dated "Thu, 18 Oct 2012 06:29:49 -0000" Date: Thu, 18 Oct 2012 13:57:04 -0400 Message-ID: <1601.1350583024@sss.pgh.pa.us> X-Pg-Spam-Score: -2.3 (--) X-Archive-Number: 201210/182 X-Sequence-Number: 34482 sams.james+postgres@gmail.com writes: > I have a file with several nul characters in it. The file itself appears to > be encoded as windows-1252, though I am not 100% certain of that. I do know > that other software (e.g. Python) can decode the data as windows-1252 > without issue. Postgres's \copy, however, chokes on the nul byte: > ERROR: unterminated CSV quoted field > CONTEXT: COPY promo_nonactive_load_fake, line 239900 Postgres doesn't support nul characters in data, so the best you could hope for here is an error message anyway. It looks to me like the immediate cause of this is that \copy reads the file with fgets() which will effectively ignore the rest of the line after a nul byte. But there are probably more issues downstream. regards, tom lane