0

In Oracle we have a function where we are using bulk collect to fetch data and store in a variable like.

      SELECT DISTINCT emp_id
      BULK COLLECT INTO v_emp_array
      FROM   emp_details;

where v_emp_array is a type:

Oracle: CREATE OR REPLACE TYPE v_emp_array IS TABLE OF VARCHAR2(4000);

Please help to get this functionality in PostgreSQL.

Being new to these, I am not able to find the correct syntax for it.

Pooja
  • 327
  • 1
  • 5
  • 20

1 Answers1

0
do $$
declare
v_emp_array varchar[];
begin
select array(select distinct emp_id from emp_details) into v_emp_array;
end;
$$;
Vinod
  • 11
  • 1
  • 1
    Code only answers are discouraged on StackOverflow. Also, try to avoid answering a duplicate question. If you can, flag it as duplicate or comment on the question as such. – philantrovert Apr 02 '18 at 12:15