PostgreSQL从text []数组列中选择最后一个数组键

时间:2015-03-16 19:30:13

标签: postgresql

我如何SELECT只显示数组列中的最后一个键?

SELECT * FROM table;

+----+---------------+
| id | col_array     |
+----+---------------+
| 1  | {"a"}         |
+----+---------------+
| 2  | {"a","b","c"} |
+----+---------------+
| 3  | {"b","d","f"} |
+----+---------------+

col_array的理想结果是:a,c,f。

1 个答案:

答案 0 :(得分:1)

使用array_upper

select col_array [array_upper(col_array, 1)] from my_table