Search code examples
postgresqlpgadminpostgresql-11

How to run a true procedure in pgAdmin and evaluate results


I haven't seen any question that covers all of what I'm asking, so for grins am posting my journey here.

The task: Run, in pgAdmin, a procedure (not a function) in Postgres. Evaluate and report back the results to the user on-screen.

For my situation, I had a procedure with the following signature:

CREATE OR REPLACE PROCEDURE sqls.transform_main(
    INOUT returnval integer)
LANGUAGE 'plpgsql'
...

How does one accomplish this?


Solution

  • Replying (with code) to Jeremy's reply...

    OK, I am seeing how your solution works. One question, though...

    I want to pass in an actual variable that is defined in such a way that I can evaluate the returned value. (Assume this this an extended script that I don't want to turn into another stored procedure or function...)

    Can I do that by your approach? I am thinking no, because by the time I've made it a script (not a single SQL call) I lose the output that I do see in your version, as you noted, in the Data Output tab.

    DO
    $$
    declare return_val integer;
    declare return_msg text;
    declare notify_msg text := 0;
    BEGIN
    call test(return_val); -- I never see what this value is unless...
    if (return_val != 0) then
        notify_msg = 'Failure (' || return_val || ')';
    else
        notify_msg = 'success!';
    end if;
    RAISE NOTICE 'Return value is %', notify_msg; -- ...unless I do something like this
    END
    $$