Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to Postgresql. I want to pass an ArrayList to the postgresql stored function. How can I pass this ArrayList to the Postgresql function using Java ?

Here is my function

CREATE OR REPLACE FUNCTION si.get_ticket_price(IN txnLookupKey TEXT[]) 
RETURNS TABLE(
 txn_lookup_key TEXT, 
 amount NUMERIC, 
 sale_code TEXT, 
 source_updt_dt_tm TIMESTAMP ) AS

$$
BEGIN
 RETURN QUERY 
  SELECT c.txn_lookup_key, 
         SUM(c.txn_qty) / 
            CASE WHEN SUM(c.txn_amount) = 0 
            THEN 1 
            ELSE SUM(c.txn_amount) 
            END, 
         max(c.sale_code), 
         CAST( max(c.source_updt_dt_tm) AS TIMESTAMP) 
  FROM si.cia_paciolan_txn_lookup c 
  WHERE c.txn_lookup_key = any( txnLookupKey ) 
         and c.active_ind = true 
  GROUP BY c.txn_lookup_key;
END;
$$

LANGUAGE PLPGSQL;
share|improve this question
    
The real question here seems to be "how do I convert an ArrayList<String> to an array of text, i.e. text[], in PostgreSQL?" –  Craig Ringer Aug 4 at 12:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.