2014-03-01 69 views
2

團隊, 我使用的是Redshift版本*(8.0.2)。在使用COPY命令加載數據時,出現錯誤: - 「字符串包含無效或不受支持的UTF8代碼點,錯誤的UTF8十六進制序列:bf(錯誤3)」。 似乎COPY試圖將UTF-8「bf」加載到VARCHAR字段中。按照亞馬遜的紅移,這個錯誤代碼3以下定義:字符串包含無效或不受支持的UTF8代碼點。錯誤的UTF8十六進制序列:

error code3: 
The UTF-8 single-byte character is out of range. The starting byte must not be 254, 255 
or any character between 128 and 191 (inclusive). 

亞馬遜recommnds以此作爲解決方案 - 我們需要去更換一個有效的UTF-8編碼序列上的字符或刪除字符。

請問如何用有效的UTF-8代碼替換字符?

當我在PG-ADMIN中檢查數據庫屬性時,它顯示編碼爲UTF-8。

請指導我如何替換輸入分隔文件中的字符。

謝謝...

+0

我們展示的代碼你使用,讓你這一點,以最小的重複例如一起,我會盡力幫助。 –

回答

2

聽起來像您的文件的編碼可能不是utf-8。您可能會嘗試我們有時使用的這種技術

cat myfile.tsv| iconv -c -f ISO-8859-1 -t utf8 > myfile_utf8.tsv 
+0

這有幫助 - 我也可以推薦[chardet](https://pypi.python.org/pypi/chardet)嘗試嗅出你的源代碼,如果這不知道。 – thyme

1

我在加載實驗的TPC-DS數據集時遇到了RedShift中的這個問題。

這裏是文檔和論壇數落我通過AWS發現:https://forums.aws.amazon.com/ann.jspa?annID=2090

這裏是明確的命令,你可以用它來解決數據轉換錯誤:http://docs.aws.amazon.com/redshift/latest/dg/copy-parameters-data-conversion.html#copy-acceptinvchars

可以明確替換無效的UTF-8或者在COPY階段通過陳述ACCEPTINVCHARS將它們全部忽略在一起。

試試這個:

copy table from 's3://my-bucket/my-path 
credentials 'aws_iam_role=<your role arn>' 
ACCEPTINVCHARS 
delimiter '|' region 'us-region-1'; 

Warnings: 
Load into table 'table' completed, 500000 record(s) loaded successfully. 
Load into table 'table' completed, 4510 record(s) were loaded with replacements made for ACCEPTINVCHARS. Check 'stl_replacements' system table for details. 

0 rows affected 
COPY executed successfully 

Execution time: 33.51s 
相關問題