PostgreSQL provides an array type. I'll show you how to use it specifically.
Creates a table with an array type field.
Create table test_array(id serial primary key, str1 int[][][]);
Insert two test data.
Insert into test_array values (1,array[[[,2],[3,4],[5,6]],[[20,30],[40,50],[70,100]]]);
Insert into test_array values (2,array[[[100,200],[300,400],[500,600]],[[2000,3000],[4000,5000],[7000,10000]]]);
Traversing without sharding,
Create or replace function sp_array2table_simple(
Anyarray
)
Returns table (element int) as
$ytt$
Declare array1 alias for $1;
x int;
Begin
Drop table if exists tmp_1;
Create temporary table tmp_1 (id int);
<<label1>> foreach x in array array1
Loop
Insert into tmp_1 values (x);
End loop label1;
Return query select * from tmp_1;
End;
$ytt$ language plpgsql;
T_girl=#select sp_array2table_simple(str1) as array_list from test_array where id = 2;
Array_list
------------
100
200
300
400
500
600
2000
3000
4000
5000
7000
10000
(12 lines of records)
Time: 7.780 ms
Traversal with fragmentation:
?
Create or replace function sp_array2table(
Anyarray
)
Returns table (element int) as
$ytt$
Declare array1 alias for $1;
x int[];
Nlen int := 0;
i int := 1;
Begin
Drop table if exists tmp_1;
Create temporary table tmp_1 (id int);
<<label1>> foreach x slice 1 in array array1
Loop
Nlen := array_length(x,1);
i := 1;
<<label2>> while i <= nlen loop
Insert into tmp_1 values (x[i]);
i := i + 1;
End loop label2;
End loop label1;
Return query select * from tmp_1;
End;
$ytt$ language plpgsql;
T_girl=#select sp_array2table(str1) as array_list from test_array where id = 2;
Array_list
------------
100
200
300
400
500
600
2000
3000
4000
5000
7000
10000
(12 lines of records)
Time: 20.139 ms
There is a system of several functions, directly to traverse,
T_girl=#select unnest(str1) as array_list from test_array where id = 2;
Array_list
------------
100
200
300
400
500
600
2000
3000
4000
5000
7000
10000
(12 lines of records)
Time: 1.002 ms
For example, array_to_string and so on.
T_girl=#select regexp_split_to_table(array_to_string(str1,','),',+') as array_list from test_array where id = 2;
Array_list
------------
100
200
300
400
500
600
2000
3000
4000
5000
7000
10000
(12 lines of records)
Time: 0.850 ms