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.
Why doesn't the first query work, and is there a cleaner way to do this than the second query?
这个怎么样:
SELECT (xpath('/my/xpath/expr', my_xml))[1] FROM my_table;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.