array_lower() 是一个系统函数,返回所请求的 数组 维度的下界。
array_lower() 在 PostgreSQL 7.4 中添加。
用法
array_lower (anyarray,integer) →integer
给定一个特定的数组(例如 ['foo','bar','baz']),array_lower() 返回第一个(最低)元素的索引,即数组的下界,默认值为 1。
postgres=# SELECT array_lower(ARRAY['foo', 'bar', 'baz'], 1);
array_lower
-------------
1
(1 row)
上面示例中的第二个参数引用了数组的维度——由于示例数组只有一个维度,因此该参数必须是 1。
也可以为数组下界指定不同的起始点,例如:
postgres=# SELECT array_lower('[0:2]={1,2,3}'::integer[], 1);
array_lower
-------------
0
(1 row)
有关更多示例,请参见下面的 示例部分。
变更历史
- PostgreSQL 7.4
- 已添加(提交 fef731d1)
示例
array_lower() 的基本执行示例
postgres=# SELECT array_lower(ARRAY[1,2,3], 1);
array_lower
-------------
1
(1 row)
将 array_lower() 与多维数组一起使用
postgres=# SELECT array_lower(array[ [1,2,3],[4,5,NULL] ], 2);
array_lower
-------------
1
(1 row)
如果提供了无效的数组维度,则返回 NULL。
postgres=# SELECT array_lower(ARRAY[1,2,3], 2) IS NULL; ?column? ---------- t (1 row)
参考资料
- PostgreSQL documentation: 数组函数
