• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase
您的位置:首页 > 数据库 >PostgreSQL > SQL Server数据迁移至PostgreSQL出错的解释以及解决方案

SQL Server数据迁移至PostgreSQL出错的解释以及解决方案

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了sql server数据迁移,sql server数据,sql server 数据类型,sql server数据恢复,sql server导出数据等相关知识,希望本文的分享对您有所帮助

问题重现:

1、PG客户端:

postgres=# create table text_test (id int,info text);
CREATE TABLE
postgres=# insert into text_test values (1,E'\0x00');
ERROR: invalid byte sequence for encoding "UTF8": 0x00
</div>

2、SQL Server产生数据

create table test_varchar(id int,name varchar(20));
insert into test_varchar values (1, 'name' + char(0));
insert into test_varchar values (1, 'name' + '');
</div>

然后通过java程序进行获取数据并插入到PG,同样会得到错误信息:

invalid byte sequence for encoding "UTF8": 0x00
</div>

首先我们认为此为gb2312转化到UTF8时,发生了无法转化的错误。经查UTF8是变长的, 1-6个字节。他的编码规则如下:

Bits Last code point Byte 1 Byte 2
Byte 3
Byte 4
Byte 5
Byte 6
7 U+007F 0xxxxxxx




11 U+07FF
110xxxxx 10xxxxxx



16 U+FFFF
1110xxxx 10xxxxxx
10xxxxxx



21 U+1FFFFF
11110xxx 10xxxxxx
10xxxxxx
10xxxxxx


26 U+3FFFFFF
111110xx 10xxxxxx
10xxxxxx
10xxxxxx
10xxxxxx

31 U+7FFFFFFF
1111110x 10xxxxxx
10xxxxxx
10xxxxxx
10xxxxxx
10xxxxxx

而0x00是符合UTF8规则的。这就使我们非常诧异。然后我们发现有两点继而确认了问题:
1、

PostgreSQL doesn't support storing NULL (\0x00) characters in text fields (this is obviously different from the database NULL value, which is fully supported).

If you need to store the NULL character, you must use a bytea field - which should store anything you want, but won't support text operations on it.

Given that PostgreSQL doesn't support it in text values, there's no good way to get it to remove it. You could import your data into bytea and later convert it to text using a special function (in perl or something, maybe?), but it's likely going to be easier to do that in preprocessing before you load it.

Source:http://stackoverflow.com/questions/1347646/postgres-error-on-insert-error-invalid-byte-sequence-for-encoding-utf8-0x0

</div>

2、

Terminating character

Indicated by

Tab

\t

This is the default field terminator.

Newline character

\n

This is the default

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • SQL Server数据迁移至PostgreSQL出错的解释以及解决方案

相关文章

  • 2017-05-11PostgreSQL安装、配置及简单使用方法
  • 2017-05-11windows PostgreSQL 9.1 安装详细步骤
  • 2017-05-11PostgreSQL 查看数据库,索引,表,表空间大小的示例代码
  • 2017-05-11PostgreSQL之分区表(partitioning)
  • 2017-05-11Debian中PostgreSQL数据库安装配置实例
  • 2017-05-11PostgreSql新手必学入门命令小结
  • 2017-09-08PostgreSQL的存储过程简单入门
  • 2017-05-11Windows下Postgresql数据库的下载与配置方法
  • 2017-05-11用PostgreSQL数据库做地理位置app应用
  • 2017-05-11PostgreSQL 创建表分区

文章分类

  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase

最近更新的内容

    • PostgreSQL教程(二):模式Schema详解
    • 15个postgresql数据库实用命令分享
    • PostgreSQL教程(四):数据类型详解
    • 初识PostgreSQL存储过程
    • PostgreSQL教程(二十):PL/pgSQL过程语言
    • PostgreSQL中的OID和XID 说明
    • PostgreSQL教程(三):表的继承和分区表详解
    • PostgreSQL中的XML操作函数代码
    • PostgreSQL 查看数据库,索引,表,表空间大小的示例代码
    • PostgreSQL教程(十六):系统视图详解

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有