3

In a plpgsql function how can I return a query and return from the function itself? If I just do return query select ... the statement after gets executed as well, so the return doesn't actually return from the whole function?

0

1 Answer 1

4

Use just return; as a single statement, example:

create or replace function my_func()
returns setof int language plpgsql as $$
begin
    return query select generate_series(1,2);
    return;
    return query select generate_series(3,4);
end $$;

select my_func();

 my_func 
---------
       1
       2
(2 rows)
Sign up to request clarification or add additional context in comments.

Comments

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.