相关疑难解决方法(0)

将postgresql数组打包成行

在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)

有更好的方法吗?

sql arrays postgresql rows

45
推荐指数
3
解决办法
6万
查看次数

标签 统计

arrays ×1

postgresql ×1

rows ×1

sql ×1