[翻译]  Can PostgreSQL select from an array returned by a function?

[CHINESE]  PostgreSQL可以从函数返回的数组中选择吗?


This query fails:

此查询失败:

SELECT xpath('/my/xpath/expr', my_xml)[1] FROM my_table

ERROR:  syntax error at or near "["

But this one works:

但是这个有效:

SELECT x[1] FROM
    (SELECT xpath('/my/xpath/expr', my_xml) as x FROM my_table) as ss

My xpath expression always returns only a single value, but the Postgres xpath function returns an array. I want to select the first value in the array. While the subselect works, it's pretty ugly.

我的xpath表达式总是只返回一个值,但Postgres xpath函数返回一个数组。我想选择数组中的第一个值。虽然subselect有效,但它非常难看。

Why doesn't the first query work, and is there a cleaner way to do this than the second query?

为什么第一个查询不起作用,是否有比第二个查询更简洁的方法?

1 个解决方案

#1


7  

How about this:

这个怎么样:

SELECT (xpath('/my/xpath/expr', my_xml))[1] FROM my_table;

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号