Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you debug functions with postgres?

Tags:

I'm using pgAdmin III 1.8.4 and finding it a harsh mistress.

When writing stored procedures (functions), there's no query compilation. So I have no idea if my function will work until I call it.

How do other people work around this deficiency? (Other than getting it right first time :p)

like image 325
Tristan Warner-Smith Avatar asked Feb 20 '09 14:02

Tristan Warner-Smith


People also ask

How do I modify a function in PostgreSQL?

To start the function editor, navigate to the desired function in the schema browser, select the 'Source Code' tab and click on the 'Edit In Function Editor' button. Alternatively, you can right-click on the function in the schema browser and select 'Edit In Function Editor'.

Can we call stored procedure from function in PostgreSQL?

PostgreSQL does not support true stored procedures (multiple result sets, autonomous transactions, and all that) though, only sql-callable user-defined functions.

What does $$ mean in PostgreSQL?

A dollar sign ($) followed by digits is used to represent a positional parameter in the body of a function definition or a prepared statement. In other contexts the dollar sign may be part of an identifier or a dollar-quoted string constant.


2 Answers

EnterpriceDB includes PL/PGSQL Debugger which you can use to step through the code.

like image 160
Quassnoi Avatar answered Sep 30 '22 18:09

Quassnoi


Write a unit test for it. Granted this won't give you debugging capability, but you should ideally have a unit test suite (and an integration test suite) that you run against your code that proves that it works... and that lets you know when something breaks.

like image 40
Akrikos Avatar answered Sep 30 '22 18:09

Akrikos