Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a task to pass arrays, records and in some cases array of records as a parameter to the stored procedures in PostgreSQL.

Any ideas?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

Postgres has very flexible handling of arrays and composite types. This may be the sort of thing you are trying to do:

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

create function my_function(arr in 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)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.