Thursday, May 12, 2016

PostgreSQL: Passing an array of record to a stored procedure

create type my_type as (val1 int, val2 int);

create function my_function(arr my_type[]) returns text language plpgsql as
$$
begin
  return arr::text;
end;
$$;

select my_function(array[row(1,2)::my_type, row(3,4)::my_type]);

    my_function
-------------------
 {"(1,2)","(3,4)"}
(1 row)