0

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

  • If you really need this feature in a 9.x version of PostgreSQL you will (1) want to compile it from source and (2) maintain the patched version of plpython yourself. The fact that you are asking here about how to do that suggests it may not be a good idea. If upgrading your version of PostgreSQL is at all possible I would recommend that instead. – Richard Huxton Aug 05 '19 at 10:52
  • Hi @RichardHuxton, Thanks for quick reply. Yes, upgrading postgres is the option too, however, there are many applications running on this db server. So, I wanted to check if there is any other way to do this. – Nilesh Navale Aug 05 '19 at 10:59

0 Answers0