Fixes passing zero dimension array
Postgres returns zero-dimensional array whenever zero-length array is
used. So it doesn't make much sense to not accept one.
This was previously accepted and then broken in
Fixes edgedb/edgedb-rust#181
@@ -224,15 +224,16 @@ cdef WriteBuffer recode_array(
frb_slice_from(&sub_buf, in_buf, in_len)
- val = hton.unpack_int32(frb_read(&sub_buf, 4)) # ndims
- if val != 1 and val != 0:
+ ndims = hton.unpack_int32(frb_read(&sub_buf, 4)) # ndims
+ if ndims != 1 and ndims != 0:
raise errors.InputDataError("unsupported array dimensions")
- out_buf.write_int32(val)
+ out_buf.write_int32(ndims)
data = frb_read(&sub_buf, 8) # flags + reserved (oid)
out_buf.write_cstr(data, 4) # just write flags
out_buf.write_int32(<int32_t>array_tid)
+ if ndims != 0:
cnt = hton.unpack_int32(frb_read(&sub_buf, 4))
out_buf.write_int32(cnt)
