Jul*_*iën 5 c# postgresql npgsql jint ravendb
在 RavenDB 5.4+ 中,我想使用 Raven 的 Npgsql 内置工厂配置一个SQL ETL 任务,将数据卸载到 PostgreSQL 数据库。我遇到的问题是我希望将整个文档 ( this) 存储在jsonb数据列中。
问题:如何实现将整个文档(例如this下面的 ETL 转换示例中的)存储到 Postgres?
我的目标是不必Foo手动指定对象的字段/列。
Postgres 表示例:
create table public.foo
(
id text,
data jsonb
);
Run Code Online (Sandbox Code Playgroud)
RavenDB 中的 ETL 转换脚本示例:
loadToFoo ({
id: id(this),
data: this // <-- the issue
});
Run Code Online (Sandbox Code Playgroud)
这会导致异常:
Npgsql.PostgresException (0x80004005): 42804: 列“data”的类型为 jsonb,但表达式的类型为文本
我尝试过以下替代方案:
data: JSON.parse(this)
Error:
System.ArgumentException: Expected string but got Symbol
---
data: JSON.stringify(this)
Error:
Npgsql.PostgresException (0x80004005): 42804: column "data" is of type jsonb but expression is of type text
Run Code Online (Sandbox Code Playgroud)
我也不确定它是否与 RavenDB 的转换逻辑有关,或者应该通过 Jint 运行时或 Postgres/Npgsql 中的某些方式来考虑解决方案。
您需要告诉 RavenDB 您想要的类型是什么。这是通过直接传递值和类型来完成的,如下所示:
loadToFoo ({
id: id(this),
data: {'Value:' this, 'Type': 'Jsonb'}
});
Run Code Online (Sandbox Code Playgroud)