@Lior539 Assuming you are talking about functions written in PL/pgSQL I share your frustrations with debugging them. Anyone reading this I strongly suggest to make use of the PLPGSQL_CHECK extension (which acts as a linter and can help you identify issues before even running the code) and PGTAP extension (which allows writing unit tests for the DB code)