Pregunta

Tengo una tarea para pasar matrices, registros, y en algunos casos matriz de registros como un parámetro para funciones en PostgreSQL.

¿Fue útil?

Solución

Postgres tiene un manejo muy flexible de arrays y tipos compuestos . Este puede ser el tipo de cosa que está tratando de hacer:

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)"} |

aquí

Licenciado bajo: CC-BY-SA con atribución
No afiliado a dba.stackexchange
scroll top