0

I have a function with parameters of numerical type, I have done the query successfully, my problems is that I do not know how to pass several parameters within the IN, where id in(parameter). The id is of type BIGINT

From JAVA I have the following query:

select parametro1, parametro2, parametro3 from function_detalls ("parameters");

Where parameters is a string type 1,2,3,4,5,6,7, ....

My question is how can I pass this type of parameter to the function?

1 Answer 1

2

Pass an array to your function and use WHERE = ANY().

For example:

CREATE FUNCTION func_test(params text[])
RETURNS SETOF test
LANGUAGE PLPGSQL
AS $$
DECLARE
BEGIN
    RETURN QUERY
    SELECT * FROM test WHERE txt = ANY(params);
END;
$$

To call:

SELECT * FROM func_test(ARRAY['hello', 'world']);

DBFiddle to show it in action

Sign up to request clarification or add additional context in comments.

1 Comment

@J Spratt I lost a bit in your answer, the parameters to send is always volatile, that is, the size varies, as I do with an array of 1000?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.