4

I am using the copy command in Postgresql and I have a line of data in a text file that is tab seperated and I would like to copy it into the db table.

I get an error saying: ERROR: invalid byte sequence for encoding "UTF8": 0x00 SQL state: 22021 Context: COPY real_acct1, line 113038

So I went to the line 113038 from the text file and copied it along with 4 or 5 neighboring lines into a new text file and behold that new data went in.

Any helpful thoughts? This is parcel data attributes info.

8
  • What is the encoding of the file? What PostgreSQL version? Commented Jan 21, 2012 at 18:49
  • @underdark Thanks. I have already encountered encoding issues and I've preprocessed the text file with python to get those encodings handled. But this seems different than the link you pointed out because if I get the one line that is throwing the error and put it in another text file then postgressql loads fine. Commented Jan 21, 2012 at 18:50
  • @filiprem I am not sure. See my comment to underdark. I was having problems with the spanish n-accented and also some weird << characters. I moved them into another text file and will load them manually. But this issue seems to be different. Thanks. Commented Jan 21, 2012 at 19:01
  • Since this question is not directly GIS-related, I think you'll find a better audience directly on stackoverflow. I'll migrate your question there. Commented Jan 21, 2012 at 20:31
  • 1
    The error message says that there is a NUL byte at this line. If you copied it into another file and saved, there is a real chance that the editor filtered out the NUL byte. A lot of text editors would do that (Windows Notepad for example). Commented Jan 22, 2012 at 3:23

1 Answer 1

2

Your problem is actually one of character encoding.

The easiest way to deal with this is running your import data through iconv (assuming you're on a unix machine).

iconv -f original_charset -t utf-8 originalfile > newfile

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.