Skip to content
Advertisement

How to edit and return a Cursor in plpgsql?

I am doing a simple query inside a function, and I need to change the values ​​of this query, but only for information. I don’t need to update the table as such. I managed to edit the values ​​but I don’t know how to return them.

And below this function will be executed

As you can see, the query does not bring me anything.

I appreciate the help and I apologize for using the google translator: D

Advertisement

Answer

If you want some result from table function, you should to fill related variables (defined inside table clause list), and then you should to use RETURN NEXT statement. It is well described by documentation.

Simple example:

Your code has another performance bug. Two nested loops over queries can be slow. You can use JOIN (in this case self join), and iterate over one cycle instead nested two.

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