Re: How to do things like \timing on in a do loop?

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: How to do things like \timing on in a do loop?
Date: 2022-10-16 09:21:35
Message-ID: Y0vNH0gxukHJB6S6@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, Oct 15, 2022 at 08:32:59PM +0100, Shaozhong SHI wrote:
> DO
> $do$
> declare
>
> j int=1;
>
> BEGIN
>
> for j in 1..100 loop
>
> \timing on
>
> select * from a_table;
>
> end loop;
>
> end
> $$;
>
>
> It appears that \timing on is not allowed in a do statement.
>
> Any alternative to do that in a do statement?

Perhaps explain what you want to do, because from this snippet it is
(for me) definitely not clear.

You're mixing postgresql code (do blocks) and psql commands (\timing).
you're trying to get timing off select, but you're not telling the code
what to do with results of the select.

So, what is the end goal in here? And how will you run it? Via psql?
Some other db access?

depesz

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Shaozhong SHI 2022-10-24 14:44:03 select only 1 pair
Previous Message Erik Brandsberg 2022-10-15 20:04:41 Re: How to do things like \timing on in a do loop?