Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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

In a function declaring RETURNS int you can:

RETURN 1;

For RETURNS SETOF int you can use:

RETURN NEXT 1;

If you declared OUT parameters, you can just:

RETURN;

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

RETURN NEXT;

The current state of all OUT parameters is returned automatically in this case.

Finally, there is the short syntax to return a whole set of rows at once:

RETURN QUERY ...

record is just a special data type that has a slightly different meaning, depending on where you use it. Like I posted in my answer to your preceding question: "Declare variable of table type in PL/pgSQL", the manual explains the record type in plpgsql here.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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