tcdi / plrust

A Rust procedural language handler for PostgreSQL
PostgreSQL License
1.1k stars 32 forks source link

How to return an array of any dimenion from pl/rust function. #399

Open thiru-baffle opened 8 months ago

thiru-baffle commented 8 months ago

We are converting the UDFs from PL/PGSQL to PL/Rust.
The following pl/pgsql function accepts an array of bigint and returns an array of bytea.

  1. create function array_encrypt(xs anyarray) returns bytea[].

    With this function, it can accept any dimension of an array and can return any dimension array by returning an array[[data::bytea][data2::bytea]].

To do this same thing in pl/rust, I have tried a few things as below:

  1. CREATE FUNCTION echo_array(a INT[]) RETURNS int[] STRICT LANGUAGE pl/rust AS -> it always expects the return type of Vec<Option>
  2. I have noticed that when the function argument is of array type, then pl/rust accepts it as Array<'_, i32>. So I tried

    CREATE FUNCTION echo_fn2(a INT[]) RETURNS Array<', i32> -> But failed to recognize the Array<'_,i32> type in pl/rust.

Could you help me, is there any options to achieve the above requirement in pl/rust?