What is the difference between RETURN NEXT and RETURN RECORD in PL/pgSQL? I find the manual quite confusing in explaining what RETURN RECORD actually does. What is a RECORD type?

2 Answers 2


While RETURN NEXT is valid plpgsql syntax, RETURN RECORD is non-existent as such. It corresponds to how you declare the return type in the function header. Read the manual about how to return from a function.

In a function declaring RETURNS int you can:


For RETURNS SETOF int you can:


If you declare OUT parameters, you can just:

-- or do nothing: OUT params are returned at the end of the function anyway

Or if you combine OUT parameters with RETURNS SETOF record - effectively the same as RETURNS TABLE (...):


The current state of all OUT parameters is returned as next row.

Finally, to return a whole set of rows at once:


record is a special data type. It's meaning depends on where you use it. Like I posted in my answer to your previous question:

The manual about the record type in PL/pgSQL.


A RETURN NEXT statement:

  • can append zero or more rows to the function's result set one by one and the rows can be modified one by one.

  • cannot exit a function while a RETURN statement can.

  • can work only in a PL/pgSQL function.

  • can work only with SETOF <sometype> or TABLE() in a RETURNS clause otherwise there are the error and the error.

*The doc explains RETURN NEXT statement in detail.

A RETURN QUERY statement:

*The doc explains RETURN QUERY statement in detail.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.