Skip to content
Advertisement

How to iterate over results of query

I am creating a function in pgsql script language, and what I want to do in this point is iterate over the results of a query and for each row do something specific. My current try is the following, where temprow is declared as temprow user_data.users%rowtype. The code in question is the following:

However I get the following error from this: ERROR: relation "temprow" does not exist. If it’s clear what I want to be done, could you point to me the right way to do it?

Advertisement

Answer

temprow is a record variable which is bound in turn to each record of the first SELECT.

So you should write:

This loop could be further simplified as a single query:

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