9

Is it possible for a PostgreSQL plpgsql function to not return anything? I've created a function, and I don't need it to return anything at all, as it performs a complex SQL query, and inserts the results of that query into another table (SELECT INTO ....). Thus, I have no need or interest in having the function return any output or value. Unfortunately, when I try to omit the RETURN clause of the function declaration, I can't create the function. Is it possible for a PostgreSQL plpgsql function to not return anything?

3 Answers 3

15

Yes - "If the function is not supposed to return a value, specify void as the return type." and also - "If you declared the function to return void, a RETURN statement can be used to exit the function early; but do not write an expression following RETURN.".

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

Comments

0

This doesn't directly answer your question, but I found it interesting that you don't need a RETURN clause if you have one or more OUT output parameters. That's obviously returning something, but allows you to "omit the RETURN" as you say.

Comments

-1

No, it must at least return null. From the PostgreSQL documentation:

A trigger function must return either NULL or a record/row value having exactly the structure of the table the trigger was fired for.

2 Comments

it is perfectly acceptable to return VOID in which instance you don't have to have it return anything.
A (PL/pgSQL) function can return void, but when the function is used as a trigger function then the function has to return something.

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.