public inbox for pgsql-novice@postgresql.org  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Subramanian,Ramachandran <ramachandran.subramanian@alte-leipziger.de>
To: pgsql-novice@lists.postgresql.org <pgsql-novice@lists.postgresql.org>
Subject: Re: SQL - How to iterate with delay in a loop
Date: Fri, 06 Mar 2026 14:20:58 +0100
Message-ID: <12a672903852221b22d90692c1d8933c054ee7b7.camel@cybertec.at> (raw)
In-Reply-To: <6c2c6ae6d61a467a91d08414e38b50c5@alte-leipziger.de>
References: <6c2c6ae6d61a467a91d08414e38b50c5@alte-leipziger.de>

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





reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-novice@postgresql.org
  Cc: laurenz.albe@cybertec.at, ramachandran.subramanian@alte-leipziger.de, pgsql-novice@lists.postgresql.org
  Subject: Re: SQL - How to iterate with delay in a loop
  In-Reply-To: <12a672903852221b22d90692c1d8933c054ee7b7.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox