0

I have created a function as below :

CREATE OR REPLACE FUNCTION demo(ids SMALLINT[])
RETURNS TABLE (processkey bigint)
AS $$
BEGIN
  RETURN QUERY SELECT b.processkey FROM your_table b WHERE id_column = ANY(ids);
END;
$$ LANGUAGE plpgsql; 

In java repository class I create below method :

List<Object[]> getData(short[] ids) {
    String strq="select * from demo(:ids)";
    Query q=entitymanager.createNativeQuery(strq);
    q.setParameter("ids",ids);
    return  q.getResultList();
}

In my controller :

short[] requestid= new short[]{1,2};
List<Object[]>response=repo.getData(requestid);
System.out.println(response);

But while executing this it gives error as Bytea cannot cast to smallint . I don't know why am getting this error

Error.o.h.e.SqlExecptionHelper-Error : cannot cast type bytea to smallint , position 26 , ExceptionHandlerExceptionResolver- javax.persistrnce.PersistenceException: SqlGrammerException : could not extract Resultset
11
  • 1
    I don't see any error in the code can you post your stacktrace if it is possible? Commented Oct 11, 2023 at 9:57
  • Also why does it assume that it is a byte data? maybe you need to solve that part. Commented Oct 11, 2023 at 9:59
  • Error.o.h.e.SqlExecptionHelper-Error : cannot cast type bytea to smallint , position 26 , ExceptionHandlerExceptionResolver- javax.persistrnce.PersistenceException: SqlGrammerException : could not extract Resultset Commented Oct 11, 2023 at 10:07
  • Strange. There is no return statement in your getData method. Also crrateNativeQuery looks suspicious. Did you post actual code? Commented Oct 11, 2023 at 10:28
  • It does have.i forget to add in here. Commented Oct 11, 2023 at 13:10

0

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.