PostgreSQL copy 时提示:ERROR: invalid byte sequence for encoding "UTF8": 0xb3

测试时使用三种文件格式:sql

ISO-8859测试

Netpbm PBM image编码

ASCIIspa

if [ $(file $filename|grep -c "ISO-8859") -gt 0 ]
then
   echo "ISO-8859" psql -c "copy $schemaname.$tbname from '$dirname/$filename' with(format 'csv', delimiter ', encoding 'ISO-8859-1')" $dbname elif [ $(file $filename|grep -c "ASCII") -gt 0 ]
then
   echo $format psql -c "copy $schemaname.$tbname from '$dirname/$filename' with(format 'csv', delimiter ', encoding 'UTF-8')" $dbname else psql -c "copy $schemaname.$tbname from '$dirname/$filename' with(format 'csv', delimiter ', encoding 'ISO-8859-1')" $dbname

这种处理方式在文件格式为ASCII时,copy中途仍然会出现编码错误提示。code

ERROR: invalid byte sequence for encoding "UTF8": 0xb3 orm

 

最后摸索发现无论什么格式,都指定为ISO-8859-1就能处理。blog

 

全包容的编码格式,都能处理:it

psql -c "copy $schemaname.$tbname from '$dirname/$filename' with(format 'csv', delimiter ', encoding 'ISO-8859-1')" $dbnameform

相关文章
相关标签/搜索