Friday , June 21 2024

PostgreSQL For loop Statement

In this article, you will learn about PostgreSQL for loop statements to iterate over a range of integers or a result set of a query.

The loop command is one of the plgpsql commands that helps us perform operations between given values.

The FOR LOOP command is one of the commands that allows us to make the operations in the Loop command easier by making them a little shorter.

General Usage is as follows

Example: 

Let’s write a 10 by 10 for loop for the numbers between 100 and 200.

Insert into table

We will create a table with a single column called loop table and print the results returned from the loop in it.

We see that our For Loop loop runs and inserts records into 10 10 databases.

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories