Postgresql 如何在单引号内为@postgres运算符替换参数

Postgresql 如何在单引号内为@postgres运算符替换参数,postgresql,jdbc,Postgresql,Jdbc,我对将两种不同的东西组合在一起有意见。我尝试了很多关于SO的建议,但没有任何效果,因此我发布了我的问题 所以要求是 我需要构建动态查询来搜索Java中的jsonb列类型 我需要使用准备好的Java语句来避免sql注入 我需要替换单引号中的参数 CLI中的此查询工作正常 select * from items where cnt @@ '$.**.text like_regex "#finance" flag "i"';

我对将两种不同的东西组合在一起有意见。我尝试了很多关于SO的建议,但没有任何效果,因此我发布了我的问题

所以要求是

我需要构建动态查询来搜索Java中的jsonb列类型 我需要使用准备好的Java语句来避免sql注入 我需要替换单引号中的参数 CLI中的此查询工作正常

select * from items where cnt @@ '$.**.text like_regex "#finance" flag "i"';                                                                    
我想参数化的部分是金融。所以当我构建这个查询时

select * from items where cnt @@ '$.**.text like_regex ? flag "i"';                                                                    
执行时,我得到以下错误

"The column index is out of range: 1, number of columns: 0." 
org.postgresql.util.PSQLException: ERROR: operator does not exist: jsonb @@ jsonb
  Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
  Position: 106
是因为?在单引号内,所以jdbc驱动程序可能无法识别为可替换参数

我能找到的最接近的问题/讨论在这篇文章中:

我已经试过了,但是由于某些原因,这对我来说不起作用。他们问我现在跑的是什么

select * from items where cnt @@ ?::jsonb 
但有了这个,我得到了以下错误

"The column index is out of range: 1, number of columns: 0." 
org.postgresql.util.PSQLException: ERROR: operator does not exist: jsonb @@ jsonb
  Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
  Position: 106
我尝试过很多其他的方法,比如转义单引号等等,但都没有真正起作用。我对PostgreSQL的了解非常有限,因此任何帮助都将不胜感激

博士后版本:13.1 Java版本:15

从cnt@?::jsonb所在的项目中选择*


@@右边的东西应该是jsonpath,而不是jsonb。因此,将其转换为jsonb显然是错误的。试着将其转换为jsonpath。

效果很好。抱歉,这似乎是我在做的蠢事:。我应该在研究生阶段提高自己的技能。救了我一天。