Home > Blockchain >  postgresql : Same raw query run faster than in function
postgresql : Same raw query run faster than in function

Time:12-11

Same query run faster outside of function but in function it runs hundred times slower and when I remove where clause it runs faster in function too but not faster than raw query. I wonder whats the problem.

RETURN QUERY (SELECT 
    t.tran_id,  t.tran_date,  t.value_date, t.statement_reference, t.debit,   t.credit,t.office_id
FROM transactions.transactions_view t
WHERE t.tran_date BETWEEN from_::date AND to_::date

 AND t.gl_account_id = gl_account_id_);

CodePudding user response:

You should try with:

RETURN QUERY EXECUTE (SELECT 
    t.tran_id,  t.tran_date,  t.value_date, t.statement_reference, t.debit, t.credit,t.office_id
FROM transactions.transactions_view t
WHERE t.tran_date BETWEEN from_::date AND to_::date
 AND t.gl_account_id = gl_account_id_);

See RETURN QUERY vs RETURN QUERY EXECUTE and PostgreSQL: Documentation

  • Related