Using query_to_xml in PostgreSQL with prepared statements

左心房为你撑大大i 提交于 2019-12-13 21:28:12

问题


I'm using PostgreSQL's function query_to_xml function to generate XML of a query result.

SELECT * FROM query_to_xml( 'SELECT * from some_table WHERE id = ?',true,false,'')

Problem is, when I use it from JDBC, with prepared Statements the '?' is ignored, so Postgres says:

"The column index is out of range..."

Is there any possible solution to pass parameters to such a query ?


回答1:


Try to move the ? outside the string literal:

SELECT * FROM query_to_xml( 'SELECT * from some_table WHERE id = '||?,true,false,'')


来源:https://stackoverflow.com/questions/14897398/using-query-to-xml-in-postgresql-with-prepared-statements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!