Thursday, May 12, 2016

PostgreSQL: Passing an array of record to a stored procedure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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)