no binary format encoder for type jsonb
还没有人认领这个 Issue。
评估
调研方向
从 copy_records_to_table 和 set_type_codec 开始,使用 binary format 重现 PostgreSQL jsonb(OID 3802)报告的失败。跟踪现有的 JSON 和数值 codec 处理,然后验证 binary format 的 jsonb 记录能够被接受,且不会出现报告中的 encoder 错误。
由索引模型根据 Issue 内容生成。
描述
-
asyncpg version: 0.29.0
-
PostgreSQL version: 16
-
Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: -
Python version: 3.11
-
Platform: 5.10.0-21-arm64 #1 SMP Debian 5.10.162-1 (2023-01-21) aarch64 GNU/Linux
-
Do you use pgbouncer?:no
-
Did you install asyncpg with pip?: yes
-
If you built asyncpg locally, which version of Cython did you use?:
-
Can the issue be reproduced under both asyncio and
uvloop?: yes
,asyncpg.exceptions._base.InternalClientError: no binary format encoder for type jsonb (OID 3802)
async def insert_binary(self, table, rows):
if rows:
rows = common_function.convert_data_type(rows, decimal.Decimal, float, )
columms = rows[0].keys()
data = []
for row_index, rows_once in enumerate(rows):
data_once = [rows_once[columns_once] for columns_once in columms]
data.append(tuple(data_once))
conn = await self.connect()
await conn.copy_records_to_table(table,records=data, columns=rows[0].keys())
await conn.fetch('SELECT 1')
await conn.close()
I've tried various methods, but I couldn't manage to insert binary data. I've tried using decoders and other approaches. It seems like it needs a binary decoder, not a text one, but I haven't figured out how to represent it in binary. I'd appreciate any help.
await conn.set_type_codec(
"jsonb",
encoder=lambda data: b"\x01" + common_function.decoder.dumps(data, False),
decoder=lambda data: common_function.decoder.loads(data[1:]),
schema="pg_catalog",
format="binary"
)
await conn.set_type_codec(
'numeric'
, encoder = lambda f: str(f).encode('utf8')
, decoder = lambda b: b.decode('utf8')
, schema='pg_catalog'
, format='binary'
)
"This also doesn't work."
"I replaced 'numeric' with 'float' (database field types), and the problem 'no binary format encoder for type numeric' disappeared. However, I couldn't figure out which format decoder is needed for JSON."
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 469
- 平均合并
- 4 天 1 小时
- 30 天内合并 PR
- 14
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MagicStack/asyncpg 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
MagicStack/asyncpg#1371 ·
-
难度 3/5 1-2 天 新手友好度 72/100
MagicStack/asyncpg#1342 ·
-
难度 3/5 1-2 天 新手友好度 56/100
MagicStack/asyncpg#1340 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 28/100
MagicStack/asyncpg#1337 ·
-
难度 4/5 3-5 天 新手友好度 42/100
MagicStack/asyncpg#1330 · 1 条评论 ·
查看 MagicStack/asyncpg 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 86/100
browser-use/browser-use#5905 ·
-
type: enhancement
难度 2/5 1-3 小时 新手友好度 68/100
ynput/ayon-python-api#363 ·
-
bug needs triage
难度 2/5 1-3 小时 新手友好度 88/100
modelscope/FunASR#3728 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
open-compass/opencompass#2655 ·