Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 导出到PostgreSQL时出现SQL Server导入和导出向导错误_Sql Server_Database_Postgresql - Fatal编程技术网

Sql server 导出到PostgreSQL时出现SQL Server导入和导出向导错误

Sql server 导出到PostgreSQL时出现SQL Server导入和导出向导错误,sql-server,database,postgresql,Sql Server,Database,Postgresql,我正在尝试使用SQL Server的导入和导出向导(SQL Server 2008 R2)导出SQL Server数据库。数据库模式在目标PostgreSQL数据库中创建得很好,大多数数据也是如此。只有当我尝试导出第一行中有NULL值的列时,它才会崩溃: 错误0xc020844b:数据流任务22:数据插入期间发生异常,从提供程序返回的消息为:Kan een object van het type System.Int32 niet converteren naar het type Syste

我正在尝试使用SQL Server的导入和导出向导(SQL Server 2008 R2)导出SQL Server数据库。数据库模式在目标PostgreSQL数据库中创建得很好,大多数数据也是如此。只有当我尝试导出第一行中有
NULL
值的列时,它才会崩溃:


错误0xc020844b:数据流任务22:数据插入期间发生异常,从提供程序返回的消息为:Kan een object van het type System.Int32 niet converteren naar het type System.Char[]。
(SQL Server导入和导出向导)

不幸的是,相关的例外是荷兰语,但它说它不能将
System.Int32
类型的对象转换为
System.Char[]
。原始SQL Server架构中的列类型在生成的PostgreSQL数据库中为
int
integer


只有当第一行中的列的值为
NULL
时,才会发生这种情况。我认为它试图根据列的第一个值推断数据类型,如果第一个值为
NULL
,则默认为
System.Char[]
。有没有办法改变这种行为,让数据的类型以与生成的PostgreSQL列的类型相同的方式推断出来(因为它这样做是正确的)?

问题似乎不在PostgreSQL方面,因此您可能应该寻找转换工具来查找错误。从psql:

test=# CREATE TABLE import (id int NOT NULL PRIMARY KEY, val1 int, val2 int);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "import_pkey" for table "import"
CREATE TABLE
test=# COPY import FROM STDIN (FORMAT CSV);
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> 1,,111
>> 2,22,222
>> \.
test=# SELECT * FROM import;
 id | val1 | val2 
----+------+------
  1 |      |  111
  2 |   22 |  222
(2 rows)

您可以尝试用SQL server中的伪值替换所有空值,并在迁移后将其替换回。@ErwinBrandstetter是的,我可以这样做,但我希望有一种更简单的方法。您可以尝试一下,看看这是否确实是问题的原因。@ErwinBrandstetter如果我这样做,它会起作用,但是我不得不这么做很烦人。是的,问题在于SQL Server附带的转换工具。我只是觉得奇怪,同一个工具正确地转换了数据库模式,但没有正确地转换数据。