ITPub博客

首页 > 数据库 > 国内数据库 > openGauss 下标生成函数

openGauss 下标生成函数

原创 国内数据库 作者:liwt_001 时间:2022-11-09 11:20:46 0 删除 编辑
  • generate_subscripts(array anyarray, dim int)

    描述:生成一系列包括给定数组的下标。

    返回值类型:setof int

  • generate_subscripts(array anyarray, dim int, reverse boolean)

    描述:生成一系列包括给定数组的下标。当reverse为真时,该系列则以相反的顺序返回。

    返回值类型:setof int

generate_subscripts是一个为给定数组中的指定维度生成有效下标集的函数。如果数组中没有所请求的维度或者NULL数组,返回零行(但是会给数组元素为空的返回有效下标)。示例:


--基本用法。

openGauss=# SELECT generate_subscripts('{NULL,1,NULL,2}'::int[], 1) AS s;
s
---
1
2
3
4
(4 rows)

--unnest一个2D数组。
openGauss=# CREATE OR REPLACE FUNCTION unnest2(anyarray)
RETURNS SETOF anyelement AS $$
SELECT $1[i][j]
  FROM generate_subscripts($1,1) g1(i),
       generate_subscripts($1,2) g2(j);
$$ LANGUAGE sql IMMUTABLE;

openGauss=# SELECT * FROM unnest2(ARRAY[[1,2],[3,4]]);
unnest2
---------
      1
      2
      3
      4
(4 rows)

--删除函数。
openGauss=# DROP FUNCTION unnest2;


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70019768/viewspace-2922521/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2022-07-07

  • 博文量
    28
  • 访问量
    15814