Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 更新jsonb列时列索引超出范围:2,列数:1错误_Postgresql_Spring Boot_Mybatis_Spring Mybatis - Fatal编程技术网

Postgresql 更新jsonb列时列索引超出范围:2,列数:1错误

Postgresql 更新jsonb列时列索引超出范围:2,列数:1错误,postgresql,spring-boot,mybatis,spring-mybatis,Postgresql,Spring Boot,Mybatis,Spring Mybatis,我试图用mybatis更新java中的jsonb列 下面是我的映射器方法 @Update("update service_user_assn set external_group = external_group || '{\"service_name\": \"#{service_name}\" }' where user=#{user} " + " and service_name= (select service_name from services wh

我试图用mybatis更新java中的jsonb列

下面是我的映射器方法

@Update("update service_user_assn set external_group = external_group || '{\"service_name\": \"#{service_name}\" }' where user=#{user} " + 
                " and service_name= (select service_name from services where service_name='Google') " )
public int update(@Param("service_name")String service_name,@Param("user") Integer user);
更新jsonb外部_组cloumn时出现以下错误

### Error updating database.  Cause: org.postgresql.util.PSQLException: The column index is out of range: 2, number of columns: 1.
### The error may involve com.apds.mybatis.mapper.ServiceUserMapper.update-Inline
对于非jsonb列,我可以用同样的方法进行更新

另外,如果我输入硬编码的值,它也适用于jsonb列

更新jsonb列时如何解决此错误?

不应将{}括在单引号中,因为它将成为文本的一部分,而不是占位符。i、 e

外部_组=外部_组| |'{服务_名称:?}'其中。。。 因此,PreparedStatement中只有一个占位符,您将得到错误

正确的方法是在SQL中连接{}。 您可能还需要显式地将文本转换为jsonb类型

@更新{ 更新服务\用户\关联集, 外部组=外部组, ||“{\service\u name\:\”{service\u name}{124;}{124;}:::jsonb, 其中user={user}和, service\u name=从service\u name='Google'}所在的服务中选择service\u name 正在执行的SQL如下所示

external_group=external_group | |'{服务名称:'| |?| |'}'::jsonb其中。。。
我正在使用PostgreSQL,上面的语法不起作用。@sagar.tarle请创建一个最小的可执行项目,如,并在GitHub上共享。然后我将研究它。@sagar.tarle似乎需要显式地将文本转换为jsonb类型。请查看更新的答案。