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 1mxEhk-00046r-D4 for pgsql-general@arkaria.postgresql.org; Tue, 14 Dec 2021 20:47:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mxEhj-000401-3m for pgsql-general@arkaria.postgresql.org; Tue, 14 Dec 2021 20:47:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mxEhh-0003zs-T5 for pgsql-general@lists.postgresql.org; Tue, 14 Dec 2021 20:47:18 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mxEhd-0005xx-Ka for pgsql-general@lists.postgresql.org; Tue, 14 Dec 2021 20:47:17 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 2001F5C0362; Tue, 14 Dec 2021 15:47:11 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 14 Dec 2021 15:47:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=c qge1tjUr+NWp5aPtTjdNcC/isPspUh7XeTJmwJExx4=; b=P6T8HmG09mlxvTkxo GzxVcOpsMmBTVCC80EQJ0wpJ72UTA8qtoyLy6HCi3176Y/dpnbas6F2CQl3OjKq4 4h+OM1nYjffIjQveOkkhjVbdI9TmC3KDGBmsQ2JWGQN4gVRNpDcAP37lq16P4Ke0 e01kmj7gLze8Im0h08exrn1YUa+ng60OzEhmGJgl5LCpuXkBMuKSQTdF9pxVAfDS wH4QWm5SXsuGy3MBOgAx1KRYagCFZGNzgx0jh5v90Q3RIS0cfxqs9H55FiLSt8Ui kkbeD/H9/+hOBQvB+b1q4+KAJNUouNIUF6F0dmJ5/02rui/DlSPOugisIo0pWpC7 xO9EQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=cqge1tjUr+NWp5aPtTjdNcC/isPspUh7XeTJmwJEx x4=; b=WzKpCL+jRWd4CW584xw5O8uks4Xp42X58SQIx0gJ3h72bBuIFWGfSNkTc KRbGKc8MzZneec1N1mQLkeZ8F+i8AOSQtU8FwkctptzJbutpytT6Bw7M3Ss51+PA R5Q6stxuO2jWOoAwSsKQX8p7lzMc/IHO425NlHIpkOPM/KJn2LXTL9JcLpN68Fkg O1voe5OQ736mmPvgW5D1ALtmctwRVwGZbi0JjCBo3feweNfLa2O5YYnhzJER7w/h W7bsIDsIN8QMYLs8uZWGRRmCXRn0HQZGptTKnGFXT3PZW1JWYWsbBajM5hoX1Meu sOAUVR4K47SLrD7pwbnIrtefBNbug== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrledtgddugedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeelkeegjefhkeetheefudevteehiedvudehkeduleet fedvffeuhedtvdegtdeffeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 Dec 2021 15:47:10 -0500 (EST) Message-ID: Date: Tue, 14 Dec 2021 12:47:09 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: Why can't I have a "language sql" anonymous block? Content-Language: en-US To: Bryn Llewellyn Cc: Tom Lane PostgreSQL , pgsql-general list References: <872342.1639428817@sss.pgh.pa.us> <79c43dc2-f0f6-1ad8-82b4-da5ba536fdf5@aklaver.com> <05E2EA9E-B353-4D69-B255-3BAAA5954936@yugabyte.com> From: Adrian Klaver In-Reply-To: <05E2EA9E-B353-4D69-B255-3BAAA5954936@yugabyte.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/14/21 11:30, Bryn Llewellyn wrote: > /Adrian Klaver wrote:/ > > /Bryn wrote:/ > > Thanks for the links to the articles on the inlining of “language sql” > functions into SQL statements that use them. (I noted “the exact > conditions which apply to inlining are somewhat complex and not well > documented outside the source code” in the PG Wiki.) This optimization > is interesting. But its discussion is orthogonal to the question that I > asked. You asked: "There must be a reason to prefer a “language sql” procedure over a “language plpgsql” procedure—otherwise the former wouldn’t be supported." I provided two reasons, or did I misread that? > It would seem, on its face, that the DO block is preferable because it > uses a single server call from the client rather than four. (Maybe it’s > two server calls if the implementation of autocommit is done client-side > by sending a follow-up “commit”.) I do know that at least some client > languages that have a PG driver allow many SQL statements to be sent in > a single call. I’ve heard that psql will do this if all the statements > are on one line. But I can’t find anything in the PG docs about this. Is > it true? And if so, where is it documented? However, this just feels far > less like a clear way to ask for what you want than a DO block. And it > would lead to unreadable code with only a small number of to-be-batched > SQL statements. Seems to work for the tests: https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/test/regress/sql/timestamp.sql;h=e011e779ea2da20393f624505ad6dea7f9582438;hb=HEAD > > All this aside, as long as DO blocks don’t allow their contained > statements to be parameterized, you anyway have to use a procedure to > get the functionality that you need. This makes my question largely > moot—as Tom implied. So I’ll simply hope that, one day, the PostgreSQL > guardians will concede that implementing this missing DO functionality > would be useful—just as the Oracle Database guardians decided three > decades ago—and bring that functionality in a future PG release. My experience is when I get to the point of needing parameters I'm pretty much going to need the other plpgsql features. I could see having it, but I do not remember seeing any/many previous posts to this list requesting it. That pushes it down to the bottom of the must haves. -- Adrian Klaver adrian.klaver@aklaver.com