如何使用 PySpark 将 JSON 列类型写入 Postgres?
How to write JSON column type to Postgres with PySpark?
我有一个 Postgresql table,它有一个数据类型为 JSONB
的列。
如何通过 JDBC 将 DataFrame
插入到 Postgresql table?
如果我有一个 UDF 将 body
列转换为 JSONB
Postgresql 数据类型,我应该使用什么对应的 pyspark.sql.types?
Postgresql Table 具有 JSONB
列:
CREATE TABLE dummy (
id bigint,
body JSONB
);
谢谢!
事实证明,如果我将 "stringtype":"unspecified"
设置为 JDBC 的属性,Postgres 将自动转换:
properties = {
"user": "***",
"password": "***",
"stringtype":"unspecified"
}
df.write.jdbc(url=url, table="dummy", properties=properties)
我有一个 Postgresql table,它有一个数据类型为 JSONB
的列。
如何通过 JDBC 将 DataFrame
插入到 Postgresql table?
如果我有一个 UDF 将 body
列转换为 JSONB
Postgresql 数据类型,我应该使用什么对应的 pyspark.sql.types?
Postgresql Table 具有 JSONB
列:
CREATE TABLE dummy ( id bigint, body JSONB );
谢谢!
事实证明,如果我将 "stringtype":"unspecified"
设置为 JDBC 的属性,Postgres 将自动转换:
properties = { "user": "***", "password": "***", "stringtype":"unspecified" } df.write.jdbc(url=url, table="dummy", properties=properties)