Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

no binary format encoder for type jsonb

Đang mở
#1,144 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
30/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
postgresql, python
Lĩnh vực
databases

Hướng nghiên cứu

Bắt đầu với copy_records_to_table và set_type_codec, tái hiện lỗi đã được báo cáo đối với PostgreSQL jsonb (OID 3802) với binary format. Theo dõi cách xử lý hiện có đối với các codec JSON và số, sau đó xác minh rằng các bản ghi jsonb ở binary format được chấp nhận mà không gặp lỗi encoder đã được báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

  • 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."

Ngôn ngữ chính
Python
Star
8.1k
Fork
469
Merge trung bình
4 ngày 1 giờ
Pull request đã merge (30 ngày)
14

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của MagicStack/asyncpg

Tất cả issue của MagicStack/asyncpg

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.