--- title: 'PL/pgSQL For Loop' page_title: 'PL/pgSQL For Loop in PostgreSQL' page_description: 'In this tutorial, you will learn about PL/pgSQL for loop statements to iterate over a range of integers and a result set of a query.' prev_url: 'https://www.postgresqltutorial.com/postgresql-plpgsql/plpgsql-for-loop/' ogImage: '/postgresqltutorial/plpgsql-FOR-loop.png' updatedOn: '2024-03-19T04:07:19+00:00' enableTableOfContents: true previousLink: title: 'PL/pgSQL While Loop' slug: 'postgresql-plpgsql/pl-pgsql-while-loop' nextLink: title: 'PL/pgSQL Exit Statement' slug: 'postgresql-plpgsql/plpgsql-exit' --- **Summary**: in this tutorial, you will learn about PL/pgSQL `for` loop statements to iterate over a range of integers or a result set of a query. ## Using PL/pgSQL for loop to iterate over a range of integers The following illustrates the syntax of the `for` loop statement that iterates over integers of a range: ```sql [ <