Postgres lo_import 从其他 table 文本数据导入大对象

Postgres lo_import large object import from other table text data

我需要将 table 中的文本数据转换为另一个 table 中的大对象数据。所以 table 结构是:-

Employee->
id (character varying(130)),name (character varying(130)), description (text)

EmployeeDetailed ->
detailed_id(character varying(130)), desc_lob (oid)

为了将所有行从 Employee table 转移到 EmployeeDetailed table,我可以 运行 执行什么查询,以便从 Employee 的 id 列填充 detailed_id 并且description 将被转换为大对象,oid 将被插入 desc_lob.

我可以使用 lo_import() 吗?

lo_import() 是客户端接口命令。您可以使用 INSERT 语句,使用 SELECT 的结果,并在该 SELECT 子句中使用 lo_from_bytea

INSERT INTO EmployeeDetailed (detailed_id, desc_lob)
SELECT id, lo_from_bytea(0, convert_to(description, 'LATIN1'))
FROM Employee

LATIN1 更改为您可能喜欢的任何编码(参见 this answer