0

I'm trying to catch exception in a postgresql stored procedure. Without my "exception when other", my procedure is working. But don't with it.

This is my code :

create or replace function test(aaa varchar)
returns table (mmm integer, xxx integer)
as $body$
declare
    ccc             varchar(250);
    ddd     integer;
    xxx     integer;
    mmm         integer;
begin

    select 
        srv_int_id
    into
        mmm
    from
        srv_service
    where
        srv_var_nom = aaa;

    ddd := 1/0;

    xxx := test2(9000,'AAA');

    return query select 
        xxx, 
        mmm;

exception
    when others then
        select ccc = 'Erreur ' || sqlstate || ' dans la procedure test.sql';
        return query select 0,0;

end;
$body$ language plpgsql;

On Squirrel, I hava this error

Error: ERREUR: la requête n'a pas de destination pour les données résultantes Indice : Si vous voulez annuler les résultats d'un SELECT, utilisez PERFORM > à la place. Où : fonction PL/pgsql p_ech_mes_lire_info_message(character varying), ligne > 44 à instruction SQL SQLState: 42601 ErrorCode: 0

But I don't understand it. Do you have an idea ? Thanks.

1 Answer 1

1

You are not using the result of the select in the exception block. The message clearly says that you must use PERFORM if you intend to run something ignoring the output (like a SELECT whose resultset you are not putting into any variable... unless that = means you want to use INTO ccc).

Sign up to request clarification or add additional context in comments.

2 Comments

return query is a form of return that allow to return table (set of records)
Thanks for your answer. It help me a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.