sql - Postgres 在 SQL Server BCP 文件的最后一个预期列之后复制错误额外数据
问题描述
我正在将数据库从 Windows 上托管的 SQL Server 2016 迁移到 Debian 上托管的 Postgres 11。
我正在使用 SQL Server 2016 中的 BCP 实用程序导出数据,并使用 COPY 命令将其导入 Postgres 11。
对于很多表它都有效,但对于某些表,即使我的文件包含相同数量的列,我也会不断收到“最后一个预期列之后的额外数据”错误。COPY 命令似乎对包含空字符串的行有问题,在 Notepad++ 中显示为“NUL”。
这是我在 SQL Server 中的表的定义。(表名和列名已更改)
Create table test (
TypeId int not null,
Name nvarchar(50) not null,
License nvarchar(50) not null,
LastChanged timestamp not null,
Id1 uniqueidentifier not null,
Id2 uniqueidentifier not null,
DescriptionCol nvarchar(256) not null default '',
ConditionCol bit not null default 0,
ConditionCol2 bit not null default 0,
ConditionCol3 bit not null default 1,
DescriptionCol2 nvarchar (2) not null default ''
)
这是 Postgres 中的表定义。
CREATE TABLE test (
typeid integer NOT NULL,
name citext COLLATE pg_catalog."default" NOT NULL,
license citext COLLATE pg_catalog."default" NOT NULL,
lastchanged bytea NOT NULL,
id1 uuid NOT NULL,
id2 uuid NOT NULL DEFAULT uuid_generate_v4(),
descriptioncol text COLLATE pg_catalog."default" NOT NULL DEFAULT ''::text,
conditioncol boolean NOT NULL DEFAULT false,
conditioncol2 boolean NOT NULL DEFAULT false,
conditioncol3 boolean NOT NULL DEFAULT true,
descriptioncol2 text COLLATE pg_catalog."default" NOT NULL
)
我以这种方式提取数据:
bcp Database.Schema.test out E:\MyFile.dat -S ServerName -U User -P Password -a65535 -c -C 65001
然后我连接到远程 Postgres 服务器并以这种方式导入数据:
\copy Schema.test FROM 'E:\MyFile.dat' (DELIMITER E'\t', FORMAT CSV, NULL '', ENCODING 'UTF8');`
现在,如果我打开在 Notepad++ 中生成的文件,我会看到“NUL”字符,这似乎是 COPY 命令无法解决的问题。
如果我尝试将一些数据放在第一行的“NUL”字符中,那么复制命令会在第三行而不是第一行上为我提供“最后一个预期列之后的额外数据”。我无法编辑文件并用其他内容替换“NUL”字符,因为我有数百个表要迁移到一些非常大的表。
我需要为 SQL Server BCP 实用程序或 Postgres COPY 命令指定一个选项才能使其工作。
解决方案
推荐阅读
- javascript - 无法通过代理通过公共获取访问私有字段
- swift - 找到海量中所有真实的索引
- snowflake-cloud-data-platform - 雪花 JS 过程
- google-cloud-vertex-ai - 如何在 Vertex AI 表格预测中分配两个或更多时间序列标识符列
- r - 简化 ifelse() 的递归使用
- android - Listview 没有堆叠在容器上
- kotlin - 共享模块中的 KMM 依赖问题
- node.js - 使用 express 和 nodeJS 的嵌套 API 调用中的错误处理
- php - 如何在 PHP 中跟踪使用 GMAIL API 发送的电子邮件的已发送、已打开、已单击、已退回、已阻止等电子邮件传递状态
- terraform - 通过 terraform 部署 helm chart 时无法传递服务注释