简体   繁体   中英

How to send list of integers into PostgreSQL function parameter?

I have a function in Repository which calls a function like this:

@Query(value="select * from my_postgres_function(?1)",nativeQuery = true)
List<Map<String, String>> getScrutinyData(List<Integer> numbers;);

In.sql file, I have that function defined as

CREATE OR REPLACE FUNCTION public.my_postgres_function(numbers Integer[]);

The query in function is something like

select * from table t where t.id in numbers;

There seems to be an error and it doesn't work. Has anyone faced this before?

I have tried to send it as String and convert the value and put it, but it did work.

This is right:

CREATE OR REPLACE FUNCTION public.my_postgres_function(numbers Integer[]);

inside the function you can use numbers like as this:

select * from table t where t.id in (select unnest(numbers))

In Java back-end side you can send your parameter using integer array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM