Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojzq3-00025r-A8 for pgsql-sql@arkaria.postgresql.org; Sun, 16 Oct 2022 09:21:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ojzq2-0006rO-3t for pgsql-sql@arkaria.postgresql.org; Sun, 16 Oct 2022 09:21:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojzq1-0006rF-Rz for pgsql-sql@lists.postgresql.org; Sun, 16 Oct 2022 09:21:41 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojzpz-0003yL-5p for pgsql-sql@lists.postgresql.org; Sun, 16 Oct 2022 09:21:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=rEBuIsQbOtqxcJLYl1XaeHshQk/Hf3LFGcGpTlU7JnY=; b=JK+SfNiHi6TtAgF6DVJyRS46WL LC43KF7Aq/ct9fmhi/IPd9W6gQMmmkeMNnMV5Gk3wx0WGcf3XLw6lnlwhx9qeO1KaUimAk7KiVI5p 9JpVHPIsT5tiZoh9SOIRFZIe5woNGlb4CO7fB3vk0kkoXahELt11yMWOiF3bP94CbluQ=; Received: from depesz by depesz.com with local (Exim 4.94.2) (envelope-from ) id 1ojzpv-00AGxH-Co; Sun, 16 Oct 2022 11:21:35 +0200 Date: Sun, 16 Oct 2022 11:21:35 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Shaozhong SHI Cc: pgsql-sql Subject: Re: How to do things like \timing on in a do loop? Message-ID: Reply-To: depesz@depesz.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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