在PostgreSQL中将数组展开成行的最快方法是什么?即
我们有:
a
-
{1,2}
{2,3,4}
Run Code Online (Sandbox Code Playgroud)
我们需要:
b
-
1
2
2
3
4
Run Code Online (Sandbox Code Playgroud)
我用的是:
select explode_array(a) as a from a_table;
Run Code Online (Sandbox Code Playgroud)
explode_array在哪里:
create or replace function explode_array(in_array anyarray) returns setof anyelement as
$$
select ($1)[s] from generate_series(1,array_upper($1, 1)) as s;
$$
Run Code Online (Sandbox Code Playgroud)
有更好的方法吗?