Closed GFuhr closed 1 year ago
This is because a composite type isn't a "scalar" and requires specific representation on the wire. Ideally, asyncpg should learn to support format="tuple"
codecs for user-defined composites, where you would only need to convert np.complex64
to a tuple of real and imaginary parts and vice-versa, e.g:
await conn.set_type_codec(
'complex',
schema='public',
encoder=lambda x: (x.real, x.imag),
decoder=lambda t: np.complex64(t[0] + 1j * t[1]),
format='tuple',
)
thanks a lot, I can't wait for this update :)
Hi,
I need for a project to store complex numbers in a database (numpy.complex64 exactly) and for that I created a postgresql composite datatype.
I was able to make it work with asyncpg in text format for simple INSERT, SELECT... after some works and patches found on previous issues report.
However for the binary format I have weird errors : asyncpg.exceptions.DatatypeMismatchError: wrong number of columns: 1082549862, expected 2
I made a "simple" python script to reproduce the issue :