Skip to content
Advertisement

How to return a custom record using return next

When I try to return a table, my results are showing up like this

rather than like this

I am assuming I am not correctly returning the rows properly. Could someone advice me how I can return my data. I tried using return query but when I evoke my function it tells me the types do not match.

Advertisement

Answer

Your function should be declared as returns setof emprecord as you are returning multiple rows.

But the whole example can be simplified by using returns table – then you don’t need the extra “return type”. You also don’t need PL/pgSQL for this. A (usually more efficient) language sql function is enough:

Online example

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement