将数组或记录传递给PostgreSQL中的函数?


Answers:


20

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 在这里

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.