two dimensional arrays not supported in postgresql 9x

248 Views Asked by At

Following is the Pl/Python function return 2D array:

CREATE FUNCTION return_multidim_py_array(x int4[]) 
  RETURNS int4[]
AS $$
  plpy.info(x, type(x))
  return x
$$ LANGUAGE plpythonu;

SELECT * FROM return_multidim_py_array(ARRAY[[1,2,3], [4,5,6]]);

With following software versions, I am getting following error:

- Plpython language
- Python 3.5.2
- PostgreSQL 9.5.17 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609, 64-bit

Error:

ERROR:  cannot convert multidimensional array to Python list
DETAIL:  PL/Python only supports one-dimensional arrays.
CONTEXT:  PL/Python function "return_multidim_py_array". (Line X)

However, on latest version of postgresql, this function is working as expected.

- Plpython language
- Python 3.7.2
- PostgreSQL 11.4 on x86_64-apple-darwin16.7.0, compiled by Apple LLVM version 8.1.0 (clang-802.0.42), 64-bit

Function returns following result:

return_multidim_py_array
-------------------------
{{1,2,3},{4,5,6}}

Problem here is, Postgres 9.x does not support 2D arrays.

I found a patch here, Here's a link!. However, I do not find mentioned files to make changes.

Can someone please help to make this work with Postgres 9.x.

Thanks

0

There are 0 best solutions below