postgresql - Create array dynamically inside begin and end -


how create array dynamically inside postgresql?

consider e.g.:

create or replace function fun( ) returns setof void $body$ declare  numeric;  begin   in 1..10   loop      //i have create array       arr1[] ,arr2[] ... based on length  end loop; end;  $body$ language plpgsql 

there special function purpose - array_fill:

 postgres=# select array_fill(0, array[10]);       array_fill        -----------------------  {0,0,0,0,0,0,0,0,0,0} (1 row)  postgres=# select array_fill('hello'::text, array[10]);                           array_fill                            ---------------------------------------------------------------  {hello,hello,hello,hello,hello,hello,hello,hello,hello,hello} (1 row)  postgres=# select array_fill(0, array[3,3]);         array_fill          ---------------------------  {{0,0,0},{0,0,0},{0,0,0}} (1 row) 

in pl/pgsql (but slower large arrays (over 100 items):

 $$ declare result int[] = '{}'; begin   in 1..10   loop     result := result || 0;   end loop;   raise notice '%', result; end; $$; 

Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -