1

How to call a postgres function with array of rowtype as parameter from Java application (the application is a Spring web application)?
Of course I can refactor my function and use several arrays of primitive types, but then on application side function call will be ugly.

CREATE OR REPLACE FUNCTION process_orders
(
  order_array orders[]
)
RETURNS bigint AS
$BODY$
BEGIN
    -- bla bla bla :)
    RETURN 0;
END;
$BODY$

LANGUAGE plpgsql;

1 Answer 1

2

I expect a function-like row constructor won't work for JDBC. Use the text representation of said parameter instead.
For instance, if your table is tbl (id int, txt text):

SELECT process_orders('{"(1,txt)","(1,txt)"}')

Or (to be unambiguous in the face of overloaded functions):

SELECT process_orders('{"(1,txt)","(1,txt)"}'::tbl[])

Example with space and special character:

SELECT process_orders('"(1,txt)","(1,\"txt with space and '\")"}')

How to determine correct syntax?

Just let Postgres show you:
SQL Fiddle.

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.