public inbox for pgsql-novice@postgresql.org  
help / color / mirror / Atom feed
From: Subramanian,Ramachandran <ramachandran.subramanian@alte-leipziger.de>
To: pgsql-novice@lists.postgresql.org <pgsql-novice@lists.postgresql.org>
Subject: SQL - How to iterate with delay in a loop
Date: Fri, 6 Mar 2026 12:07:05 +0000
Message-ID: <6c2c6ae6d61a467a91d08414e38b50c5@alte-leipziger.de> (raw)

Hello,

  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.

I am completely new to Postgres and may have overlooked something simple.

I would be grateful for your help.


LG

Ram


drop table time_zone_demo;
create table time_zone_demo
(
  ID_COLUMN SERIAL PRIMARY KEY,
  SAVED_TS_NO_TZ TIMESTAMP,
  SAVED_TS_WITH_TZ TIMESTAMPTZ,
  SAVED_DATE DATE,
  SAVED_TIME TIME
);

Insert into time_zone_demo (SAVED_TS_NO_TZ,SAVED_TS_WITH_TZ,SAVED_DATE,SAVED_TIME)
values (now(),now(),current_date,current_time) ;

select pg_sleep(1);

Insert into time_zone_demo (SAVED_TS_NO_TZ,SAVED_TS_WITH_TZ,SAVED_DATE,SAVED_TIME)
values (now(),now(),current_date,current_time) ;

select pg_sleep(1);

do $$
begin
        for rec in 1..25
            loop
            perform pg_sleep(1);
            Insert into time_zone_demo (SAVED_TS_NO_TZ,SAVED_TS_WITH_TZ,SAVED_DATE,SAVED_TIME)
            values (now(),now(),current_date,current_time) ;
            end loop;
end;
$$;


Freundliche Grüße

i. A. Ramachandran Subramanian
Zentralbereich Informationstechnologie

Alte Leipziger Lebensversicherung a.G.


Hallesche Krankenversicherung a.G.





Alte Leipziger Lebensversicherung a.G., Alte Leipziger-Platz 1, 61440 Oberursel
Vors. des Aufsichtsrats: Dr. Walter Botermann · Vorstand: Christoph Bohn (Vors.), Dr. Jürgen Bierbaum (stv. Vors.), Frank Kettnaker, Dr. Jochen Kriegmeier, Alexander Mayer, Christian Pape, Wiltrud Pekarek, Udo Wilcsek
Sitz Oberursel (Taunus) · Rechtsform VVaG · Amtsgericht Bad Homburg v. d. H. HRB 1583 · USt.-IdNr. DE 114106814





 
Hallesche Krankenversicherung a.G.,  Löffelstraße 34-38, 70597 Stuttgart
Vors. des Aufsichtsrats: Dr. Walter Botermann · Vorstand: Christoph Bohn (Vors.), Dr. Jürgen Bierbaum (stv. Vors.), Frank Kettnaker, Dr. Jochen Kriegmeier, Alexander Mayer, Christian Pape,
Wiltrud Pekarek, Udo Wilcsek
Sitz Stuttgart · Rechtsform VVaG · Amtsgericht Stuttgart HRB 2686 · USt.-IdNr. DE 147802285
Beiträge zu privaten Kranken- und Pflegekrankenversicherungen unterliegen nicht der Versicherungsteuer (§ 4 Nr. 5 VersStG) · Versicherungsleistungen sowie Umsätze aus Versicherungsvertreter-/Maklertätigkeiten sind umsatzsteuerfrei
 



 
Die Pflichtangaben der ALH Gruppe gemäß § 35a GmbHG bzw. § 80 AktG finden Sie hier: https://www.alte-leipziger.de/impressum 





______________________

ALH Gruppe
Alte Leipziger-Platz 1, 61440 Oberursel
Tel.: +49 (6171) 66-4882
Fax: +49 (6171) 66-800-4882
E-Mail: ramachandran.subramanian@alte-leipziger.de
www.alte-leipziger.de
www.hallesche.de



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: ramachandran.subramanian@alte-leipziger.de, pgsql-novice@lists.postgresql.org
  Subject: Re: SQL - How to iterate with delay in a loop
  In-Reply-To: <6c2c6ae6d61a467a91d08414e38b50c5@alte-leipziger.de>

* 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