我有一项任务可以将数组,记录和在某些情况下传递记录数组作为PostgreSQL中功能的参数。

有帮助吗?

解决方案

Postgres具有非常灵活的处理 数组复合类型. 。这可能是您要做的事情:

create type my_type as (val1 integer, val2 integer);
create function my_function(arr my_type[]) returns text language plpgsql as $$
begin
  return arr::text;
end;$$;
select my_function(array[row(1,2),row(3,4)]::my_type[]);
| my_function       |
| :---------------- |
| {"(1,2)","(3,4)"} |

dbfiddle 这里

许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top