Re: SQL - How to iterate with delay in a loop

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: "Subramanian,Ramachandran" <ramachandran(dot)subramanian(at)alte-leipziger(dot)de>, "pgsql-novice(at)lists(dot)postgresql(dot)org" <pgsql-novice(at)lists(dot)postgresql(dot)org>
Subject: Re: SQL - How to iterate with delay in a loop
Date: 2026-03-06 13:20:58
Message-ID: 12a672903852221b22d90692c1d8933c054ee7b7.camel@cybertec.at
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, 2026-03-06 at 12:07 +0000, Subramanian,Ramachandran wrote:
> I am trying to insert some rows into a table with a delay between each insert.
> I have a simple table with a ID column and some Date-Time columns.
>  
> The first two inserts work as expected and insert two rows, each one second apart.
>  
> However the do loop inserts 25 more rows, with the same timestamp.

Use clock_timestamp()::time instead of current_time.
current_time returns the same value for each call in the same
database transaction. Think of it as "transaction start time".

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Subramanian,Ramachandran 2026-03-06 18:24:01 AW: SQL - How to iterate with delay in a loop
Previous Message Subramanian,Ramachandran 2026-03-06 12:07:05 SQL - How to iterate with delay in a loop