在PostgreSQL中使用带预准备语句的query_to_xml [英] Using query_to_xml in PostgreSQL with prepared statements

查看:391
本文介绍了在PostgreSQL中使用带预准备语句的query_to_xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PostgreSQL的函数query_to_xml函数生成查询结果的XML。

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,'')

问题是当我在JDBC中使用它,并使用预准备的语句忽略?,因此Postgres说:

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 ?

推荐答案

尝试将移至字符串文字之外:

Try to move the ? outside the string literal:

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

这篇关于在PostgreSQL中使用带预准备语句的query_to_xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆