如何使用Springboot将数字列表传递给postgresql函数

8xiog9wr  于 2022-12-12  发布在  PostgreSQL
关注(0)|答案(1)|浏览(132)

我有一个postgresql的函数,它接收一个bigint的列表作为参数之一。我试图从我的Springboot应用程序调用它,但我不知道如何传递列表。
我的postgresql函数如下所示:

public.delete_organization_info(orgid bigint, orgdataids bigint[], orginfotype character varying)

下面是从我的Springboot存储库中调用的函数:

@Query(nativeQuery = true, value = "SELECT 'OK' from delete_organization_info(:orgId, :orgInfoIds, :orgInfoType)")
String deleteOrganizationInfoUsingDatabaseFunc(@Param("orgId") Long orgId,
                                               @Param("orgInfoIds") List<Long> orgInfoIds,
                                               @Param("orgInfoType") String orgInfoType);

当我用一个空列表执行函数时,一切正常,但是如果填充列表,就会抛出一个错误

function delete_organization_info(bigint, bigint, character varying) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.

有人能帮我知道我该怎么做吗

hs1ihplo

hs1ihplo1#

环顾四周,我终于找到了该怎么做:

@Query(nativeQuery = true, value = "SELECT 'OK' from delete_organization_info(:orgId, cast(string_to_array(cast(:orgInfoIds as varchar) , ',') as bigint[]), :orgInfoType)")
String deleteOrganizationInfoUsingDatabaseFunc(@Param("orgId") Long orgId,
                                                   @Param("orgInfoIds") String orgInfoIds,
                                                   @Param("orgInfoType") String orgInfoType);

相关问题